[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Struct packing/alignment problems
From: |
Leon Woestenberg |
Subject: |
Re: [lwip-users] Struct packing/alignment problems |
Date: |
Tue, 04 May 2004 22:58:40 +0200 |
User-agent: |
Mozilla Thunderbird 0.5 (Windows/20040207) |
Hello all,
Timmy Brolin wrote:
Leon wrote:
OK, we all seem to agree on the fact that types should always be
aligned on their natural alignment boundaries.
The real question is whether the compiler is allowed to add *extra*
padding (for performance reasons or whatever).
Agreed.
There is never a performance reason to add extra padding. As long as a
type is aligned on it's natural boundary or higher, performance is
allways the same.
I'am fairly certain the ANSI C standard specify that a compiler should
pad struct fields to their natural boundaries. If we can only verify
this...
>
Yes, the standard does specify that struct fields must be aligned to
their natural boundaries (and specifies those for known primitive
types). I am quite sure of that.
But even if the standard specifies this, the compiler is still allowed
to add extra padding, as long as the fields still comply with the above.
struct bla {
char beep;
int some;
};
Nothing prevents the compiler from adding 3 padding bytes inbetween
those fields. The int will still be naturally aligned.
I remember the packing stuff being added for *some* reason, although
I cannot remember the specific compiler or platform.
The reason was most probably the troublesome unalignment caused by the
14 byte ethernet header.
If that solely was the case *and* we know for sure that all compiler
should choose the *smallest* padding that fulfills natural alignment,
we can remove the pack directives.
Regards,
Leon.
- Re: [lwip-users] Struct packing/alignment problems, (continued)
- Re: [lwip-users] Struct packing/alignment problems, Will Tucker, 2004/05/02
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/03
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/03
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, K.J. Mansley, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, d99tibr, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Leon Woestenberg, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems,
Leon Woestenberg <=
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/05
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/05
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/05
- Re: [lwip-users] Struct packing/alignment problems, K.J. Mansley, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Kieran Mansley, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Leon Woestenberg, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/04
- RE: [lwip-users] Struct packing/alignment problems, Chris Jones, 2004/05/04