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: Wed, 05 May 2004 20:56:12 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)

Mountifield, Tony wrote:

Hi All

I don't have a strong opinion one way or the other about removing the packing 
macros, but I wanted to reply to one point:

The macros will have to remain in the code for the Ethernet
ARP header, if I understand that correctly, so it really
isn't worth worrying about.
This is no longer correct. Since the sipaddr and dipaddr fields were changed 
from struct ip_addr to struct ip_addr2, they now only have 16-bit alignment 
requirements (this is why they were changed) ...

... so long as compilers don't try to insert padding before and after struct A 
in struct B in the following example:

struct A {
        u16_t x[2];
};

struct B {
        u16_t p;
        struct A q;
        u16_t r;
};

Hopefully:

offsetof(p) is 0
offsetof(q.x[0]) is 2
offsetof(q.x[1]) is 4
offsetof(r) is 6
sizeof(struct B) is 8

Cheers,
Tony

Actually, I think you are on to something here... Someone said that gcc for arm puts all structs on 4 byte boundarys in order to use the efficient load and store multiple instructions... I have not considered this. It would surely break the etharp struct. Of course the problem can be fixed by simply replacing the ipaddr2 struct with a u16_t ip[2] array, so it's not that hard to solve.

Timmy





reply via email to

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