title: Does this violate strict aliasing or pointer alignment rules?
body: <p>I'm swapping bytes in a char buffer:</p>
  
  <pre><code>char* data; // some char buffer
  uint16_t* data16 = reinterpret_cast&lt;uint16_t*&gt;(data);
  
  // For debugging:
  int align = reinterpret_cast&lt;uintptr_t&gt;(data) % alignof(uint16_t);
  std::cout &lt;&lt; "aligned? " &lt;&lt; align &lt;&lt; "\n";
  
  for (size_t i = 0; i &lt; length_of_data16; i++) {
  #if defined(__GNUC__) || defined(__clang__)
    data16[i] = __builtin_bswap16(data16[i]);
  #elif defined(_MSC_VER)
    data16[i] = _byteswap_ushort(data16[i]);
  #endif
  }
  </code></pre>
  
  <p>I'm casting from <code>char*</code> to <code>uint16_t*</code>, which raises a flag because it's casting to a more strictly aligned type.</p>
  
  <p>However, the code runs correctly (on x86), even when the debugging code prints 1 (as in, not aligned). In the assembly I see <code>MOVDQU</code>, which I take to mean that the compiler recognizes that this might not be aligned.</p>
  
  <p>This looks similar to <a href="https://stackoverflow.com/questions/13881487/should-i-worry-about-the-alignment-during-pointer-casting">this question</a>, where the answer was "this is not safe." Does the above code only work on certain architectures and with certain compilers, or is there a subtle difference between these two questions that makes the above code valid?</p>
  
  <p>(Less important: consistent with what I've read online, there's also no noticeable perf difference between aligned and unaligned execution of this code.)</p>