title: Union initialization
body: <p>What are the rules that govern the uninitialized bytes of a union ? (Assuming some are initialized)</p>
  
  <p>Below is a 32 bytes union of which I initialize only the first 16 bytes via the first member.
  It seems the remaining bytes are zero-initialized. That's great for my use case but I am wondering what's the rule behind this - I was expecting garbage.</p>
  
  <pre><code>#include &lt;cstdint&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  union Blah {
     struct {
        int64_t a;
        int64_t b;
     };
     int64_t c[4];
  }
  
  int main()
  {
     Blah b = {{ 1, 2 }}; // initialize first member, so only the first 16 bytes.
  
     // prints 1, 2, 0, 0 -- not 1, 2, &lt;garbage&gt;, &lt;garbage&gt;
     cout &lt;&lt; b.c[0] &lt;&lt; ", " &lt;&lt; b.c[1] &lt;&lt; ", " &lt;&lt; b.c[2] &lt;&lt; ", " &lt;&lt; b.c[3] &lt;&lt; '\n';
  
     return 0;
  }
  </code></pre>
  
  <p>I've compiled on GCC 4.7.2 with <code>-O3</code> <code>-Wall</code> <code>-Wextra</code> <code>-pedantic</code> (that last one required giving a name to the anonymous struct). That hopefully should save me from being lucky.</p>
  
  <p>I've also tried to overlay two variables with two different scopes on the stack but gcc didn't give them the same address.</p>
  
  <p>I've also tried replacing the array by another struct in that case that would have mattered, but it didn't change anything.</p>
  
  <p>I can't access online compilers from here, they're blocked by my work.</p>