structure members of packed structures
Hans-Peter Nilsson
hp@bitrange.com
Tue Jul 15 03:40:00 GMT 2003
On Mon, 14 Jul 2003, Nathan Sidwell wrote:
> 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.
Only for members whose type does not include a "packed"
qualifier, and only when used in an expression whose type also
doesn't include a packed qualifier. For example, this should
remain valid and supported:
struct Packed s1;
struct __attribute__ ((packed)) Unpacked *p1;
p1 = &s1.u;
> 2) force u to be aligned (ignoring the packed attribute).
No, that'd be very broken.
brgds, H-P
More information about the Gcc
mailing list