title: Is using a structure without all members assigned undefined?
body: <p>Consider this code in block scope:</p>
  
  <pre><code>struct foo { unsigned char a; unsigned char b; } x, y;
  x.a = 0;
  y = x;
  </code></pre>
  
  <p>C [N1570] 6.3.2.1 2 says “If the lvalue designates an object of automatic storage duration that could have been declared with the <strong>register</strong> storage class (never had its address taken), and that object is uninitialized (not declared with an initializer and no assignment to it has been performed prior to use), the behavior is undefined.”</p>
  
  <p>Although a member of <code>x</code> has been assigned a value, no assignment to <code>x</code> has been performed, and its address has not been taken. Thus, it appears 6.3.2.1 2 tells us the behavior of <code>x</code> in <code>y = x</code> is undefined.</p>
  
  <p>However, if we had assigned a value to every member of <code>x</code>, it would seem unreasonable to consider <code>x</code> to be uninitialized for the purposes of 6.3.2.1 2.</p>
  
  <p>(1) Is there anything in the standard which, strictly speaking, causes 6.3.2.1 2 not to apply to (make undefined) the code above?</p>
  
  <p>(2) Supposing we were modifying the standard or determining a reasonable modification to 6.3.2.1 2, are there reasons to prefer one of the following over the others? (a) 6.3.2.1 2 does not apply to structures. (b) If at least one member of a structure has been assigned a value, the structure is not uninitialized for purposes of 6.3.2.1 2. (c) If all named<sup>1</sup> members of a structure have been assigned a value, the structure is not uninitialized for purposes of 6.3.2.1 2.</p>
  
  <h3>Footnote</h3>
  
  <p><sup>1</sup> Structures may have unnamed members, so it is not always possible to assign a value to every member of a structure. (Unnamed members have indeterminate value even if the structure is initialized, per 6.7.9 9.)</p>