From 6.3.2.1 (emphasis mine)
If the lvalue designates an object of automatic storage duration that could have been declared with the register 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.
That means, that if the automatic object could not be declared with the register storage class (have it's address taken):
int x;
printf("just a dummy pointer print %p", &x); //taking the address to break 6.3.2.1 UB condition
if (x == 2)
{
print("x uninitialized value: %d", x);
}
Than according to 6.3.2.1 there is no undefined behavior in if (x == 2) where I use the value of the uninitialized object.
If that is true, and there is no UB here, than what is the defined behaviour? what should I expect in x according to the standard?
In this case, because
xhas had it's address taken, the behavior is not strictly undefined. The value ofxat this point is indeterminate. This means the value is either a trap representation or unspecified.If
xhappens to contain a trap representation then the behavior is undefined, otherwise the value is unspecified which means that any valid value could be printed.Also, most systems you're likely to come across don't have any padding bits in integer types, meaning there are no trap representations on that implementation and the value will always be unspecified.
The relevant passages from the C standard:
Section 3.19:
Section 6.7.9p10: