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

Florian Weimer (fw@cygnus.stuttgart.netsurf.de)
14 Jun 1999 16:35:32 +0200


Olaf Titz <olaf@bigred.inka.de> writes:

> > This behavior is *NOT* a bug in Egcs. A C compiler is free to reorder
> > the members of a structure (except the first one, and the last one if it
>
> So how it is possible to write programs which access data structures
> in an externally prescribed binary format (e.g. filesystems,
> executable headers, communications protocols)? Does this standard
> effectively mean that the only way is *((foo *)base+pos) on char *base?

Strictly speaking, yes. I'm not sure whether reordering the structure
members is really permitted, but padding can be quite arbitrary in
order to match the requirements of the target machine. (It's certainly
non-trivial for a programming language to get such representation
issues right. The only programming language I know which tries to do
that is Ada 95.)

But nevertheless, there's a bug in egcs because no padding occurs in this
case (sizeof(t) is still 4), so the result should be anything but 0x12.
I guess it's an aliasing issue. (Ada certainly got this one right. ;)

-
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/