This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Double abstract class Inheritance concern.
- From: Chris Lattner <sabre at nondot dot org>
- To: Tiago Stein <tiago at lisha dot ufsc dot br>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 28 Mar 2004 19:42:26 -0600 (CST)
- Subject: RE: Double abstract class Inheritance concern.
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/