Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In C 1999, it is not directly an error to use an uninitialized object. (Your quotes from Annex J are not a normative part of the standard; they are just informative.) An uninitialized object with automatic storage duration has an indeterminate value. For some objects, that value may be a trap representation, so using it may result in undefined behavior.</p> <p>However, for some objects, it is possible to determine that an uninitialized object cannot have a trap value. For example, an <code>unsigned char</code> cannot have a trap value, and the exact-width signed integer types defined in <code>stdint.h</code> cannot have trap values (because they are two’s complement with no padding bits). For other types, it may be that properties defined by your C implementation cause them not to have trap values. Using an uninitialized <code>int X</code> does not have defined behavior in all C 1999 implementations (but does in some), but using an uninitialized <code>unsigned char X</code> does.</p> <p>In C 2011, this text was added in 6.3.2 2: “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.” Therefore, in C 2011, both <code>X = X;</code> and <code>X;</code> have undefined behavior.</p> <hr> <p>History/background:</p> <p>The C 2011 change supports a Hewlett-Packard machine which has a special flag for certain registers that indicates whether the register contents are valid or not. The machine can generate an exception if a register is used while its contents are invalid. Hence, if the compiler assigns the <code>X</code> of <code>unsigned char X</code> to such a register, using the register when it is invalid may cause an exception in the machine even though there is no <code>unsigned char</code> trap value.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload