P
pemo
Ambiguous?
I have a student who's asked me to explain the following std text (esp. the
footnote).
6.2.6.1.5
Certain object representations need not represent a value of the object
type. If the stored
value of an object has such a representation and is read by an lvalue
expression that does
not have character type, the behavior is undefined. If such a representation
is produced
by a side effect that modifies all or any part of the object by an lvalue
expression that
does not have character type, the behavior is undefined.41) Such a
representation is called a trap representation.
Footnote
41) Thus, an automatic variable can be initialized to a trap representation
without causing undefined behavior, but the value of the variable cannot be
used until a proper value is stored in it.
On hearing him explain what he *thought* it meant, I've come to the
conclusion that the standard's either badly worded, or else I've been using
an incorrect term when I teach.
For example, I've gone to great pains to draw a distinction between
initialization vs. assignment - int i = 10, as opposed to int i; i = 10;
However, I also realize that I've *said* that autos are *initialized* with
unknown values, or garbage. Nevertheless, I must have said the latter a lot
less than the former - as the student certainly read 'programmer specified
initialization' for 'an automatic variable can be initialized' into the
sense of the footnote's text.
Let me paraphrase footnote 41 with the substance of what they were saying:
41) Thus, an automatic variable can be *explicitly initialized* to a trap
representation without causing undefined behavior, but the value of the
variable cannot be used until a proper value is stored in it.
I.e., the student thought that a *trap representation* was something
useful - I guess they were thinking of it as a kind of guard mechanism, that
could somehow benefit them.
Once explained, they were quite happy, but it's made me think that I ought
not to use the word initialized when talking about autos, or else that the
footnote should perhaps be reworded to something like:
* Thus, an automatic variable can be initialized by the implementation to a
trap representation .
* Thus, an automatic variable can be set to a trap representation by the
implementation .
* Thus, an automatic variable can be covertly initialized to a trap
representation .
* Thus, an automatic variable's value can be initialized to any arbitrary
value, it can be initialized to a trap representation .
Or some better wording?
BTW, is it just me, and do others object to 'can' where 'may' is more
semantically accurate [and 'better' English]?
I have a student who's asked me to explain the following std text (esp. the
footnote).
6.2.6.1.5
Certain object representations need not represent a value of the object
type. If the stored
value of an object has such a representation and is read by an lvalue
expression that does
not have character type, the behavior is undefined. If such a representation
is produced
by a side effect that modifies all or any part of the object by an lvalue
expression that
does not have character type, the behavior is undefined.41) Such a
representation is called a trap representation.
Footnote
41) Thus, an automatic variable can be initialized to a trap representation
without causing undefined behavior, but the value of the variable cannot be
used until a proper value is stored in it.
On hearing him explain what he *thought* it meant, I've come to the
conclusion that the standard's either badly worded, or else I've been using
an incorrect term when I teach.
For example, I've gone to great pains to draw a distinction between
initialization vs. assignment - int i = 10, as opposed to int i; i = 10;
However, I also realize that I've *said* that autos are *initialized* with
unknown values, or garbage. Nevertheless, I must have said the latter a lot
less than the former - as the student certainly read 'programmer specified
initialization' for 'an automatic variable can be initialized' into the
sense of the footnote's text.
Let me paraphrase footnote 41 with the substance of what they were saying:
41) Thus, an automatic variable can be *explicitly initialized* to a trap
representation without causing undefined behavior, but the value of the
variable cannot be used until a proper value is stored in it.
I.e., the student thought that a *trap representation* was something
useful - I guess they were thinking of it as a kind of guard mechanism, that
could somehow benefit them.
Once explained, they were quite happy, but it's made me think that I ought
not to use the word initialized when talking about autos, or else that the
footnote should perhaps be reworded to something like:
* Thus, an automatic variable can be initialized by the implementation to a
trap representation .
* Thus, an automatic variable can be set to a trap representation by the
implementation .
* Thus, an automatic variable can be covertly initialized to a trap
representation .
* Thus, an automatic variable's value can be initialized to any arbitrary
value, it can be initialized to a trap representation .
Or some better wording?
BTW, is it just me, and do others object to 'can' where 'may' is more
semantically accurate [and 'better' English]?