This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Differences in struct size when compiling C vs. C++
- From: inaky dot gonzalez at intel dot com
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 16 Jan 2002 20:06:11 -0800
- Subject: Differences in struct size when compiling C vs. C++
Hi people
Tried this with gcc and g++ versions 2.95.4 and 3.0.3. I am looking
for some enlightment on why the struct's sizes are so wildly different
in C and in C++:
Compile with gcc:
$ gcc kk.c -o kk -Wall
output is: sizeof (struct A) 4, sizeof (struct B) 0
now with G++:
$ g++ kk.c -o kk -Wall
output is: sizeof (struct A) 8, sizeof (struct B) 1
Why? :) I would expect this if there were vtables around, but I am
afraid there aren't any. Can anybody give me some insight? [pls copy
me, as I am not subscribed to the list]
Thanks!
PS: Great compiler, though :)
-- begin kk.c...
#include <stdio.h>
struct A
{
int d;
struct {} c;
};
struct B
{
struct
{
} c;
};
int main (void)
{
printf ("sizeof (struct A) %d, sizeof (struct B) %d\n",
sizeof (struct A), sizeof (struct B));
return 0;
}
--
naky @ somewhere in time -- e-ssing PQ even++