Am 09/10/2011 05:53 AM, schrieb Stefan Ram:
> John Temples <> writes:
>> On 2011-09-08, Kenneth Brody <> wrote:
>>> Okay, I can't find C&V, but as I recall, accessing a union via anything
>>> other than the one last written to is UB.
>> It was ID (not UB) in C90, but that was removed in C99.
>
> Annex J, J.1 »unspecified behavior«, p1, of ISO/IEC
> 9899:1999 (E) still contains:
>
> »The following are unspecified: (...)
>
> -- The value of a union member other than the last one
> stored into (6.2.6.1).«
This annex is not normative and just refers to the reasons why this
might be UB with the paragraph number.
I think the common understanding is that reading a member to which it
was not written is UB *if* the value is a trap representation for that
member. Since unsigned char may not have a trap representation it is
save to access that member.
Jens
|