Post by email@example.com
It seems use of
can be reduced in Len by
They mean different things ...
They are both expressions of type 'int'. It's entirely up to the
implementation whether they have the same value.
... (if that makes sense since both a formally
The first expression has undefined undefined behavior for at least one
reason, and possibly as many as three, depending upon the implementation:
"A pointer to an object type may be converted to a pointer to a
different object type. If the resulting pointer is not correctly aligned
68) for the referenced type, the behavior is
undefined." (18.104.22.168p7). There's no guarantee that "4321" is correctly
aligned to store an int.
"An object shall have its stored value accessed only by an lvalue
expression that has one of the following types:" (6.5p7). The following
list of types does not include anything that covers this case.
"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." (22.214.171.124p5). Whether "4321" contains the representation of a
valid int depends upon the implementation, the standard provides no
In contrast, the second expression is covered by:
"The value of an integer character constant containing more than one
character (e.g., 'ab'), or containing a character or escape sequence
that does not map to a single-byte execution character, is
It seems to me reasonably plausible that the implementation-define value
of '1234' might be the same as that of *(int*)"4321".