public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Chris Lattner <sabre@nondot.org>
To: Tiago Stein <tiago@lisha.ufsc.br>
Cc: gcc@gcc.gnu.org
Subject: RE: Double abstract class Inheritance concern.
Date: Mon, 29 Mar 2004 14:03:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.44.0403281937360.23968-100000@nondot.org> (raw)


Tiago Stein wrote:
> class A{};
> class B :public A{};
> class C: public A{ int g; };
> class D: public B, public C {
>   unsigned int foo;
> };
> Why sizeof class D is 12? Should not be 8?

I believe the reason is that the ABI does not permit multiple different
instances of A to be located at the same address, even if they have zero
size.  If the size of the structure was 8, all of "A", "B", and "A" would
have offset zero.

I'm not sure WHY this is required, but this is the reason it happens at
least.  A declaration of "A X[100];" allocates 100 bytes as
a result of the same rule.

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/

             reply	other threads:[~2004-03-29  1:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-29 14:03 Chris Lattner [this message]
2004-03-29 17:16 ` Nathan Sidwell
2004-03-29 18:49   ` Joe Buck
  -- strict thread matches above, loose matches on Subject: below --
2004-03-29 13:57 Tiago Stein
2004-03-29 15:15 ` Alexandre Oliva

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=Pine.LNX.4.44.0403281937360.23968-100000@nondot.org \
    --to=sabre@nondot.org \
    --cc=gcc@gcc.gnu.org \
    --cc=tiago@lisha.ufsc.br \
    /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).