This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: structure members of packed structures


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]