Jens Gustedt, who is involved in the C standardization, has addressed this in an answer on SO.
The executive summary is that there:
Reading uninitialized memory is not necessarily undefined behavior in C.
There are exactly two reasons things that can go wrong:.
- The type has trap representations, and that happens to be the representation in that memory location;
- AAn object with automatic storage duration (i.e., a local variable happens toor a parameter) may be held in a register. The platform hasreason this is UB is that there are platforms which have special provisions to prevent read before write from registers, as an error detection.
UB is restricted to these two possibilities. We know that there are no trap representations. If your variable does not have automatic storage duration, or if you take its address, — which prevents it from being in a register — you are safe.