Subject: Re: gcc optimizer bug in netbsd-1-6 on alpha (gcc 2.95.3 20010315 (release) (NetBSD nb3))
To: None <tech-toolchain@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-toolchain
Date: 08/16/2003 01:28:55
>>> [...] it is, of course, possible to write the earlier example in a
>>> standard conforming fashion.
>> How?  I can't see any way short of allocating a struct in_addr and
>> copying.
> I'm not going to pretend that it is pretty, but this should work for
> all C compilers:
> [...code that assumes you can store into one member of a union and
> fetch from a different one...]

I don't think such code is standard-conforming.  I haven't read the
standard, but everyone who has and from whom I've heard on the subject
has said this; K&Rv2 agrees, stating that "the results are
implementation-dependent if something is stored as one type and
extracted as another", in the main body of the book, and "[i]n general,
a member of a union may not be inspected unless the value of the union
has been assigned using that same member" (there is an exception for
struct elements that share an initial sequence of members), in the
reference material in Appendix A.

Of course, it will probably work on any machine on which the
pointer-cast version would have traditionally worked.  But that's not
the same thing as its being standard-conforming, not at all.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B