public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@codesourcery.com>
To: Chris Lattner <sabre@nondot.org>
Cc: Tiago Stein <tiago@lisha.ufsc.br>, gcc@gcc.gnu.org
Subject: Re: Double abstract class Inheritance concern.
Date: Mon, 29 Mar 2004 17:16:00 -0000	[thread overview]
Message-ID: <4067D6DD.1060607@codesourcery.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0403281937360.23968-100000@nondot.org>

Chris Lattner wrote:
> 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.

It is a C++ language requirement that no two logically distinct objects
of the same type have the same address.

BEWARE. GNU C has an empty struct extension to C, that does not obey
the same rules.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk


  reply	other threads:[~2004-03-29  7:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-29 14:03 Chris Lattner
2004-03-29 17:16 ` Nathan Sidwell [this message]
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=4067D6DD.1060607@codesourcery.com \
    --to=nathan@codesourcery.com \
    --cc=gcc@gcc.gnu.org \
    --cc=sabre@nondot.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).