Subject: Re: gcc optimizer bug in netbsd-1-6 on alpha (gcc 2.95.3 20010315 (release) (NetBSD nb3))
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Ian Lance Taylor <>
List: tech-toolchain
Date: 08/15/2003 22:01:19
der Mouse <mouse@Rodents.Montreal.QC.CA> writes:

> > At the risk of sounding condescending, I'll point out that 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:

	union { int32 i; struct in_addr a; } inet = { 0 };

	printf("parse_address(): inet addr given: [%s]\n",

If you can restrict yourself to gcc, this works too:

	union int_in_addr { int32 i; struct in_addr a; };

	printf("parse_address(): inet addr given: [%s]\n",
	       inet_ntoa(((union int_in_addr) { 0 }).i));

which is horribly ugly but can be hidden by a macro.  That 0 doesn't
have to be a constant, it just has to be assignment compatible with

Jonathan Stone <jonathan@DSG.Stanford.EDU> writes:

> Still, maybe it gives Ian some idea what the griping's about.

I do understand that it should be possible to write code which changes
types without copying through a temporary variable--that is, it should
be possible to type pun portably and safely.  In fully standard
conformant C, this now requires using a union type.

I don't claim to know the best solution for the larger issue.  For
kernel builds it's easy enough to use -fno-strict-aliasing.  For other
uses, when the new version of gcc is imported into the userland, I
dunno.  I think different groups will want different defaults.