From: Alexandre Oliva <aoliva@redhat.com>
To: Sam Lantinga <slouken@devolution.com>
Cc: gcc@gcc.gnu.org
Subject: Re: C++ bug in structure packing and inheritance
Date: Sat, 15 Dec 2001 23:57:00 -0000 [thread overview]
Message-ID: <or3d2bwr2i.fsf@free.redhat.lsd.ic.unicamp.br> (raw)
In-Reply-To: Sam Lantinga's message of "Sat, 15 Dec 2001 23:30:50 -0800"
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
next prev parent reply other threads:[~2001-12-16 7:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-15 23:40 Sam Lantinga
2001-12-15 23:57 ` Alexandre Oliva [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-12-15 15:07 Sam Lantinga
2001-12-15 16:09 ` Daniel Berlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=or3d2bwr2i.fsf@free.redhat.lsd.ic.unicamp.br \
--to=aoliva@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=slouken@devolution.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).