title: Is zero initialization of structures guaranteed to wipe padded areas?
body: <p>Suppose I have the following structure:</p>
  
  <pre><code>typedef struct
  {
      unsigned field1 :1;
      unsigned field2 :1;
      unsigned field3 :1;
  } mytype;
  </code></pre>
  
  <p>The first 3 bits will be usable but <code>sizeof(mytype)</code> will return <code>4</code> which means 29 bits of padding.
  My question is, are these padding bits guaranteed by the standard to be zero initialized by the statement:</p>
  
  <pre><code>mytype testfields = {0};
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>mytype myfields = {1, 1, 1};
  </code></pre>
  
  <p>Such that it's safe to perform the following <code>memcmp()</code> on the assumption that bits 4..29 will be zero and therefore won't affect the comparison:</p>
  
  <pre><code>if ( memcmp(&amp;myfields, &amp;testfields, sizeof(myfields)) == 0 )
      printf("Fields have no bits set\n");
  else
      printf("Fields have bits set\n");
  </code></pre>