cody said:
When both variables in the union starts at the same address, writing to one
and reading from the other is safe.
Nonsense. *Every* variable in a union starts at the same
address (every addressable variable, that is: bit-fields have
no addresses as far as C is concerned).
Note the special guarantee:
[#5] With one exception, if the value of a member of a union
object is used when the most recent store to the object was
to a different member, the behavior is
implementation-defined.68) One special guarantee is made in
order to simplify the use of unions: If a union contains
several structures that share a common initial sequence (see
below), and if the union object currently contains one of
these structures, it is permitted to inspect the common
initial part of any of them anywhere that a declaration of
the completed type of the union is visible. Two structures
share a common initial sequence if corresponding members
have compatible types (and, for bit-fields, the same widths)
for a sequence of one or more initial members
The special guarantee applies only to union members
that happen to be structs, and only to structs if they
"share a common initial subsequence." The union you
exhibited contained no structs at all, and is not covered
by the special guarantee.
Are you having trouble understanding the English in
which the Standard is written? You appear to be posting
from a .de address, which might indicate that your native
language is German. The great number of grammatical errors
in your written English makes me think you must be American,
but if not -- well, your English is better than my German,
but perhaps not equal to the task of deciphering Standardese.