This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: structure members of packed structures
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: Hans-Peter Nilsson <hp at bitrange dot com>
- Cc: gcc at gcc dot gnu dot org, Mark Mitchell <mark at codesourcery dot com>, dalej at apple dot com
- Date: Tue, 15 Jul 2003 09:49:12 +0100
- Subject: Re: structure members of packed structures
- Organization: Codesourcery LLC
- References: <Pine.BSF.4.44.0307142207420.4585-100000@dair.pair.com>
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