title: Do I understand C/C++ strict-aliasing correctly?
body: <p>I've read <a href="http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html" rel="nofollow noreferrer">this article about C/C++ strict aliasing</a>. I think the same applies to C++. </p>
  
  <p>As I understand, strict aliasing is used to rearrange the code for performance optimization. That's why two pointers of different (and unrelated in C++ case) types cannot refer to the same memory location. </p>
  
  <p>Does this mean that problems can occur only if memory is modified? Apart of possible problems <a href="https://stackoverflow.com/questions/7320766/where-can-i-find-documentation-on-c-memory-alignment-across-different-platforms">with memory alignment</a>.</p>
  
  <p>For example, handling network protocol, or de-serialization. I have a byte array, dynamically allocated and packet struct is properly aligned. Can I <code>reinterpret_cast</code> it to my packet struct? </p>
  
  <pre><code>char const* buf = ...; // dynamically allocated
  unsigned int i = *reinterpret_cast&lt;unsigned int*&gt;(buf + shift); // [shift] satisfies alignment requirements
  </code></pre>