On 8/2/05, Dave Korn <[EMAIL PROTECTED]> wrote:
> There are two separate issues here:
>
> 1) Is the base of the struct aligned to the natural alignment, or can the
> struct be based at any address
The base of the struct is aligned to the natural alignment, four bytes
in this case.
> 2) Is there padding between the struct members to maintain their natural
> alignments (on the assumption that the struct's base address is aligned.)
There is no padding. The structure is defined as
__attribute__((packed)) to explicitly remove the padding. The result
is that gcc knows the unaligned four byte member is at an offset of
two bytes from the base of the struct, but uses a four byte load at
the unaligned address of base+2. I don't expect...
p->unaligned = n;
... to work, but I definitely expect
memcpy(&p->unaligned, &n, sizeof p->unaligned);
to work. The second case is being optimised to the first case though
and generating and unaligned store.
Cheers,
Shaun