Re: Packing of structure fields and whole structs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I think you're saying that I can declare something that is unaligned:

   char c;
   struct foo f;  // unaligned

and then operate on it locally:

   f.a++;

because gcc knows that f.a is unaligned and on a machine that doesn't
do unaligned accesses it can generate appropriate byte-shuffling code.
But if I take its address:

   func(&f.a);

it won't work, because func() assumes that the pointer it is passed is
aligned. Is this correct?

The Linux people have read this in the gcc docs:

  Specifying this attribute [packed] for `struct' and `union' types is equivalent
to specifying the `packed' attribute on each of the structure or union members.

I think this is almost, but not quite, true - specifying the attribute on the struct itself also affects packing when the struct is used, not just the packing of the fields themselves.

Do people agree that this bit of the docs needs tweaking?

Phil.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux