From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Larmour To: Grant Edwards Cc: ecos-discuss@sources.redhat.com Subject: Re: [ECOS] How to stop gcc padding structs??? Date: Mon, 29 Jan 2001 09:49:00 -0000 Message-id: <3A75AD28.3F252CD3@redhat.com> References: <20010128124058.A9989@visi.com> X-SW-Source: 2001-01/msg00454.html Grant Edwards wrote: > > I'm again fighting with gcc trying (and failing) to get it to > stop putting padding bytes into structs. Have any eCosians > figured out how to prevent gcc from padding structs? > > I ran into this problem before and gave up, finally having to > use hand-calculated constants instead of "sizeof (struct foo)" > in numerous places. For example, it's impossible to define an > Ethernet header structure that ends up having a size of 14 > bytes! > > In the following example, gcc insists that each of the "high" > structs occupies four bytes despite my putting a "packed" > attribute evryplace that doesn't generate a syntax warning. It's generally non-portable to rely on struct layout matching hardware, and just because gcc can be coerced to do it doesn't make it wise, nor guarantee it on different architectures (or different versions of gcc!). It is better practice to use accessor macros instead. And no, I know Red Hat don't always practice what we preach, but we *should*. Jifl -- Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062 Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine