This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: structure members of packed structures
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Nathan Sidwell <nathan at codesourcery dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: 14 Jul 2003 14:39:29 -0700
- Subject: Re: structure members of packed structures
- Organization: CodeSourcery, LLC
- References: <3F12D31A.1030800@codesourcery.com>
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