This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Double abstract class Inheritance concern.
- From: Tiago Stein <tiago at lisha dot ufsc dot br>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 28 Mar 2004 20:19:57 -0300 (BRT)
- Subject: Double abstract class Inheritance concern.
Hy! I have question concerning inheritance of empty classes.
Supose that I have:
Class A{
};
Class B: public A{
unsigned int foo1;
};
because of C++ constraints on object sizes.. sizeof(A) is 4 (I am in a
32bit PC).
In class B, due to the attribute.. this extra size form A is supressed. So
sizeof B= 4 too..
Until here everything is OK, but... given:
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? Why the extra size from the
empty classes is not eliminated this time? Is this due to any rules in the
standard? I passed hours looking for it but found nothing that could
obligate so. This behavior is causing some real nasty side-effects in our
operating system due to memory restrictions in our embedded targets.
So, can someone explain me why of this? Maybe I am leaving something wrong
pass at my design if there is any rule that dictates this behavior.
Thanks for any help.