This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ bug in structure packing and inheritance
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Sam Lantinga <slouken at devolution dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: 16 Dec 2001 05:40:37 -0200
- Subject: Re: C++ bug in structure packing and inheritance
- Organization: GCC Team, Red Hat
- References: <E16FVl4-0000nD-00@twomix.devolution.com>
On Dec 16, 2001, Sam Lantinga <slouken@devolution.com> wrote:
>> struct a {
>> };
>> struct b : public a {
>> float x;
>> float y;
>> };
>> struct c : public a {
>> b data;
>> float z;
>> };
>> size of c = 16 (should be 12)
> Interestingly, if either b or c are not derived from a, or the order
> of b and z within c is swapped, c ends up being the correct size.
> I spent a few hours mucking about in class.c, and my uneducated guess
> is that the overlay of the base class a followed by the overlay of the
> base class a (in b) is what's causing the incorrect sizing of c.
It's actually correct. The sub-object a of class c must have
a different address from the sub-object a of class b, the first data
member of class c. Thus, data's offset in c must be non-zero.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me