title: Struct Reordering by compiler
body: <p>Suppose I have a struct like this:</p>
  
  <pre><code>struct MyStruct
  {
    uint8_t var0;
    uint32_t var1;
    uint8_t var2;
    uint8_t var3;
    uint8_t var4;
  };
  </code></pre>
  
  <p>This is possibly going to waste a bunch (well not a ton) of space.  This is because of necessary alignment of the <code>uint32_t</code> variable.</p>
  
  <p>In actuality (after aligning the structure so that it can actually use the <code>uint32_t</code> variable) it might look something like this:</p>
  
  <pre><code>struct MyStruct
  {
    uint8_t var0;
    uint8_t unused[3];  //3 bytes of wasted space
    uint32_t var1;
    uint8_t var2;
    uint8_t var3;
    uint8_t var4;
  };
  </code></pre>
  
  <p>A more efficient struct would be:</p>
  
  <pre><code>struct MyStruct
  {
    uint8_t var0;
    uint8_t var2;
    uint8_t var3;
    uint8_t var4;
    uint32_t var1;
  };
  </code></pre>
  
  <p>Now, the question is:</p>
  
  <p>Why is the compiler forbidden (by the standard) from reordering the struct?</p>
  
  <p>I don't see any way you could shoot your self in the foot if the struct was reordered.</p>