This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
size of derived classes - misfeature of gcc?
- To: gcc-help at gcc dot gnu dot org, gcc at gcc dot gnu dot org
- Subject: size of derived classes - misfeature of gcc?
- From: Christian Szegedy <szegedy at or dot uni-bonn dot de>
- Date: Mon, 7 May 2001 15:45:11 +0200
Hi!
I've got a question regarding the size and type management of gcc.
Suppose that I ompile the follwoing programm using gcc 2.95.2 or 2.95.3:
-------------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
class A
{
public:
};
class B : public A
{
public:
int i;
};
class C
{
public:
int i;
};
void main()
{
printf("%u %u %u\n",(unsigned)sizeof(A),
(unsigned)sizeof(B),
(unsigned)sizeof(C));
}
-------------------------------------------------------------------------------
Then, I would except that C and B have both size 4, and therefore the output
should be:
1 4 4
The result of this run is:
1 8 4
for some reason I don't understand.
Other compilers (e.g. xlC under AIX) produce the expected output above.
Of course this is no bug, since the generated code runs without errors.
But it can pose a significant memory overhead in practical cases in which
A has some static functions and data which is shared by several classes which
are small, but have a lot of instances (the case I actually have).
Is there some important reason for gcc to behave in this way?
Are the future versions of gcc going to have this misfeature?