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: Mon, 26 Apr 2004 19:05:13 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)

K.J. Mansley wrote:

On Mon, 2004-04-26 at 14:53, address@hidden wrote:
Quoting "K.J. Mansley" <address@hidden>:

On Mon, 2004-04-26 at 11:47, Jani Monoses wrote:
That's alot of work you have done there.
A decent solution to this alignment problem is really needed, because as
it is now, lwip is incompatible with most 32bit embedded CPUs.(!!) (Such
as ARM, TI DSPs, ...)
more correctly incompatible with some compilers. lwip works fine on ARM
using gcc.

Quite.  I wonder if the effort to get lwip to work with the compilers
that currently have problems could be better spent getting the compilers
to work with packed structs!  I doubt this is feasible though, so we are
going to have to address this recurrent problem sooner or later.

Kieran
gcc must do some very weird stuff to get unaligned packed structures to work on ARM.

gcc does weird things full stop!

lwip currently depends highly on compiler specific extensions to compile. Structure packing for unaligned memory access is not ANSI C. Don't blaim the compilers when it is the code that is wrong!

If you can suggest a way to ensure the layout of a struct in ANSI C,
without reducing all structs to byte arrays and so moving the complexity
into the rest of the code, that would be great.

Easy. I did some research and found theese two ANSI C requirements:
1: It isn't permitted for a type to have an alignment requirement larger than its own size.
2: Struct members must be laid out in the declared order.

Hence, if we make the structs properly aligned (ie. all structs on 4byte alignments), and no "gaps" in the structs, then the layout will be the same on all ANSI C compatible compilers/systems who support 8bit types. (lwip does not work on systems without support for 8bit types anyway).

 There have been many
suggestions so far on this topic, but none is perfect, so there will
have to be compromise somewhere.  On this issue I think I agree with you
(albeit from a practical standpoint) that we won't get support for
packed structs from all compilers, so we have to provide some means to
work around it.

It's just a matter of aligning the structs properly.

Timmy





reply via email to

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