structure members of packed structures
Mark Mitchell
mark@codesourcery.com
Mon Jul 14 22:35:00 GMT 2003
On Mon, 2003-07-14 at 08:58, Nathan Sidwell wrote:
> Given,
>
> struct Unpacked { int i; };
>
> struct __attribute__ ((packed)) Packed
> {
> char c;
> Unpacked u;
> };
>
> where should 'u' be placed? Our current behavour is to pack it so that
> Unpacked's members are unaligned.
>
> options
> 1) continue this behaviour, but prevent taking references/address of u or
> any of its members.
I assume that the point is that for:
Packed p;
p.u.i = 3;
the compiler can figure out that it has to use an unaligned write?
I think this solution is better than ...
> 2) force u to be aligned (ignoring the packed attribute).
... this one, because it will avoid changing the ABI for existing code.
If you don't hear any objections in the next day or two, go ahead and
implement (1).
Thanks!
--
Mark Mitchell <mark@codesourcery.com>
CodeSourcery, LLC
More information about the Gcc
mailing list