Skip to main content
added 246 characters in body
Source Link

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:.

  1. The type has trap representations, and that happens to be the representation in that memory location;
  2. 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.

Jens Gustedt, who is involved in the C standardization, has addressed this in an answer on SO.

The executive summary is that there are two reasons things can wrong:

  1. The type has trap representations, and that happens to be the representation in that memory location;
  2. A local variable happens to be held in a register. The platform has 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, you are safe.

Jens Gustedt, who is involved in the C standardization, has addressed this in an answer on SO.

The executive summary:

Reading uninitialized memory is not necessarily undefined behavior in C.

There are exactly two things that can go wrong.

  1. The type has trap representations, and that happens to be the representation in that memory location;
  2. An object with automatic storage duration (i.e., a local variable or a parameter) may be held in a register. The reason 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.

Source Link

Jens Gustedt, who is involved in the C standardization, has addressed this in an answer on SO.

The executive summary is that there are two reasons things can wrong:

  1. The type has trap representations, and that happens to be the representation in that memory location;
  2. A local variable happens to be held in a register. The platform has 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, you are safe.