This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: attribute "unpadded"
- From: Jamie Lokier <egcs at tantalophile dot demon dot co dot uk>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc at gcc dot gnu dot org, Alexandre Oliva <aoliva at redhat dot com>
- Date: Tue, 27 Aug 2002 03:10:00 +0100
- Subject: Re: RFC: attribute "unpadded"
- References: <3627294541.1030124478@[192.168.0.103]>
Mark Mitchell wrote:
> This comes up in C++ like so:
>
> struct A { virtual void f(); char c; };
> struct B : public A { char c2 };
Here in C++, `sizeof(struct A)' is 8, and `sizeof(struct B)' is also 8.
> Here, the size of B is 8, not 12, because "c2" is packed into
> the tail padding of A. If A were "unpadded", you could express
> this in C as:
>
> struct A __attribute__((unpadded)) { void *vptr; char c; };
> struct B { struct A __base; char c2; };
This does _not_ express the same thing in C, because this C version of
`sizeof(struct A)' is 5.
For this reason, Alexandre Oliva's suggestion to use the attribute in
the definition of `struct B' to control the layout of `struct B' make
more sense to me. Not because it's type-theoretically right, but simply
because that gives the same results as C++.
-- Jamie