Subject: Re: Strange C compiler code generation
To: Peter Teichmann <teich-p@Rcs1.urz.tu-dresden.de>
From: Richard Earnshaw <rearnsha@buzzard.freeserve.co.uk>
List: port-arm32
Date: 02/25/2001 00:30:06
It turns out that the reason for the difference between NetBSD and linux
is that on linux, structures are, by default, aligned to a 32-bit
boundary, even if they are composed solely of elements with less alignment
than that. On netbsd, structures are aligned to a byte boundary if no
field within the structure requires a larger alignement. Hence
#pragma pack(1)
struct test {
int a,b;
};
#pragma pack()
is equivalent to writing
struct test {
int a,b __attribute__((packed));
}
If you really want to force the structures to be internally packed, but
word aligned, you will have to change the code to
#pragma pack(1)
struct test {
int a,b;
} __attribute__((aligned(32)));
#pragma pack()
But for the above case, there then seems little point in using the packed
pragma in the first place.
R.