[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: |
Wed, 05 May 2004 21:24:25 +0200 |
User-agent: |
Mozilla Thunderbird 0.5 (Windows/20040207) |
Hello Jani,
could you please test run the program below to see how the nested struct
is aligned under arm-gcc?
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.
This piece of code should show the actual alignments under GCC when
using nested structs.
#include <stdio.h>
#include <stddef.h>
#if 1
#define PACKED __attribute__ ((packed))
#else
#define PACKED
#endif
struct A {
u16_t x[2];
} PACKED;
struct B {
u16_t p;
struct A q;
u16_t r;
} PACKED;
int main ()
{
printf ("offsetof(p) = %d\n", offsetof(p));
printf ("offsetof(q.x[0]) = %d\n", offsetof(q.x[0]));
printf ("offsetof(q.x[1]) = %d\n", offsetof(q.x[1]));
printf ("offsetof(r) = %d\n", offsetof(r));
printf ("sizeof(struct B) = %d\n", sizeof(struct B));
return 0;
}
/*
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
*/
Thanks, Leon.
RE: [lwip-users] Struct packing/alignment problems, Mountifield, Tony, 2004/05/04
RE: [lwip-users] Struct packing/alignment problems, Mountifield, Tony, 2004/05/05
RE: [lwip-users] Struct packing/alignment problems, K.J. Mansley, 2004/05/05
RE: [lwip-users] Struct packing/alignment problems, Mountifield, Tony, 2004/05/06