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


Hans-Peter Nilsson wrote:
On Mon, 14 Jul 2003, Nathan Sidwell wrote:

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;
Lik Mark has said, it is hard to do this *and* prevent
 struct Unpacked *p2 = &s1.u;
because building the ADDR_EXPR loses the unalignedness information.
The 'proper' fix is to propagate an unaligned attribute, but I understand
there have been objections in the past to doing that kind of thing.

The original problem manifested in C++ with reference binding to
such a packed field. In C++ reference binding happens much more quietly
(there is no '&' screaming at you in the source.)
I could restrict to reference binding.

Dale Johannesen wrote:
> Contingent on STRICT_ALIGNMENT, please.  Unaligned accesses are not
> a problem on all architectures.
good point.

Another question. What about
struct __attribute__((packed)) Foo
{
  T m;
};

here m happens to fall at an aligned address, and the size of Foo happens
to be a multiple of that alignment. Should m be DECL_PACKED or not?

nathan

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
         The voices in my head said this was stupid too
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk



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