Re: egcs-1.1.2 ping bug also causes miscompilation of pcbit isdn driver

Kernel Stuffs (kernel@gladden-fields.demon.co.uk)
Sun, 13 Jun 1999 22:40:06 +0100


On Sun, Jun 13, 1999 at 06:37:49PM +0200, Tygrys wrote:
> Lars Heete wrote:
>
> > --------------------- test case ----------------------
> > #include <stdio.h>
> > int main(int argc, char **argv) {
> > struct {char c1, c2, c2, 4;} t;
> > t.c4 = 0x78; t.c3 = 0x56; t.c2 = 0x34; t.c1 = 0x12;
> > printf("0x%x\n", *((unsigned long*) &t));
> > return 0;
> > }
> >
> > gives 0x12 with egcs-1.1.2 on i386, instead of 0x78563412.
> But only when compiled with optimization...
>
Yeah, but this is busted C code anyway. The variables and
pointers are incompatible and you deserve what you get.
There are NO garantees when you stick 4 chars in a struct
that the compiler will put them in same long. In fact
I know for a fact at least two of the compilers at work
will align the chars on word boundaries.

Graeme

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/