How to stop gcc padding structs???

Michael Meissner meissner@cygnus.com
Mon Jan 29 10:16:00 GMT 2001


On Mon, Jan 29, 2001 at 05:48:14PM -0000, David Korn wrote:
> 
> >> True.  I suppose for maximum portability I should just use
> >> pointer arithmatic with hard-wired offsets.  It's just so ugly.
> >
> >Which of course will not work so well if your device is put into a non-x86
> or
> >non-ppc that traps when given an unaligned pointer (ie, a normal RISC
> >machine).
> 
>   IOW, for maximum portability, you must memcpy every struct element larger
> than a byte into an object of the correct type, then use ntoh(l,s) whatever
> to handle endian-ness, and only then reference it.

The other way is to pick up each individual byte and or/shift them together.
I've thought about in the past having GCC recognize such loads and turn them
into a single unaligned load operation (possibly an unaligned load and reverse
byte operation).  This is how BFD handles things.

-- 
Michael Meissner, Red Hat, Inc.  (GCC group)
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482


More information about the Gcc mailing list