This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How to stop gcc padding structs???


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]