P
H
O
T
O
B
Y
M
O
V
I
E
S
T
O
R
E
/
R
E
X
/
S
H
U
T
T
E
R
S
T
O
C
K
a trap representation. An unspecified
value is a valid value of the relevant
type where the C standard imposes no
requirements on which value is chosen
in any instance. The phrase “in any in-
stance” is unclear. The word instance
is defined in English as “a case or oc-
currence of anything,” but it is unclear
from the context what is occurring.
The obvious interpretation is that the
occurrence is a read.
9 A trap represen-
tation is an object representation that
need not represent a value of the object
type. Note that an unspecified value
cannot be a trap representation.
If a stored value of an object has a
trap representation and is read by an
lvalue expression that does not have
character type, the behavior is unde-
fined. Consequently, an automatic
variable can be assigned a trap repre-
sentation without causing undefined
behavior, but the value of the variable
cannot be read until a proper value is
stored in it.
Annex J. 2, “Undefined behavior,”
summarizes incompletely that behav-
ior is undefined in the following cir-
cumstances:
˲ A trap representation is read by an
lvalue expression that does not have
character type.
˲ The value of an object with auto-
matic storage duration is used while it
is indeterminate.
The second undefined behavior is
much more general (at least with re-
spect to objects with automatic stor-
age duration), because indeterminate
values include all unspecified values
and trap representations. This (incor-
rectly) implies that reading an inde-
terminate value from an object that
has allocated, static, or thread storage
duration is well-defined behavior un-
less a trap representation is read by an
lvalue expression that does not have
character type.
According to the current WG14
Convener, David Keaton, reading an
indeterminate value of any storage
duration is implicit undefined behav-
ior in C, and the description in Annex
J. 2 (which is non-normative) is incom-
plete. This revised definition of the
undefined behavior might be stated as
“The value of an object is read while it
is indeterminate.”
Unfortunately, there is no consen-
sus in the committee or broader com-
munity concerning uninitialized reads.
Memarian and Sewell conducted a sur-
vey among 323 C experts to discover
what they believe about the properties
that systems software relies on in prac-
tice, and what current implementa-
tions provide.
5 The survey gathered the
following responses to the question,
Is reading an uninitialized variable or
struct member (with a current main-
stream compiler):
˲ undefined behavior? 139 (43%)
˲ going to make the result of any
expression involving that value unpre-
dictable? 42 (13%)
I SEE VARIABLES
UNINITIALIZED