lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Struct packing/alignment problems


From: Timmy Brolin
Subject: Re: [lwip-users] Struct packing/alignment problems
Date: Tue, 04 May 2004 22:17:32 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)


Hello all,

Timmy Brolin wrote:


Why would they be put on 4 byte boundaries? The natural boundary of u16s is 2 bytes, not 4 bytes. Putting a u16 on a 4 byte boundary changes nothing.

>
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...
I have been looking for a copy of the official ANSI C standard document.

If a compiler is free
to add extra padding (i.e. other than for alignment reasons) we need
to keep it from doing this (through packing).

Can we give live examples of extranous padding?

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.

Timmy






reply via email to

[Prev in Thread] Current Thread [Next in Thread]