Subject: Re: GNU config.guess and netbsd{aout,elf,}
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
List: tech-toolchain
Date: 11/23/1999 22:29:11
In message <199911240548.AAA06647@Twig.Rodents.Montreal.QC.CA>,
der Mouse writes:


	u_short * buf = (u_short *) /* short-alingned char array */

>>> 	u_short VOLATILE rem;
>>> 	rem = 0;
>>> 	*(VOLATILE char *)&rem = buf[len-1];
>
>> The result of dereferencing a casted pointer is explicitly
>> implementation-defined in ANSI C.  It was never defined at all in K&R
>> C.  So at best this is non-portable code.

In what sense? It assumes 8-bit byte-addressible machines.  Given that,
can you name an implementation where this didn't work as intended?

>Is it any less portable than other similar goop we already depend on,
>like the way a softc has to begin with a "struct device"?

Until the egcs duffers changed the gcc implementation: no.  After
that, without the volatiles: yes, its less portable in that it no
longer works without the volatiles.  A friend telles me that OpenBSD
moved to compiling their kernels with -fnostrict-aliasing, due to
similar gotchas, but thats just hearsay.
Your point is well made, though.


>I also suspect that the above must "work" because of special cases for
>adding and removing qualifiers in casts, and the special status of
>"char *" (and "void *") as generic pointers.

Nope. Without the volatiles, it no longer works. The aliasing of rem
in not handled as existing practice had led the author of the code to
expect. (okay, i havent chkeced the assembly output yet, or even
-fnostrict-alias but it looks like an alias gotcha).