This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to stop gcc padding structs???
- To: David Korn <dkorn at pixelpower dot com>
- Subject: Re: How to stop gcc padding structs???
- From: Michael Meissner <meissner at cygnus dot com>
- Date: Mon, 29 Jan 2001 13:16:28 -0500
- Cc: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
- References: <718D38CAB6E0D011B2C90060970C28A5642647@EXCHANGESERVER>
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