GCC 2.96 shows bogus memory allocation when allocating some given structs?
Claudio Lavecchia
Claudio.Lavecchia@eurecom.fr
Thu Jul 29 14:28:00 GMT 2004
Hello GCC ppl,
I am trying to compile a really simple test program on my redhat using
gcc 2.96.
//----------------BEGIN TEST PROGRAM----------------
#include <stdio.h>
struct S1
{
char a[6];
};
struct S2
{
char a[6];
int b;
};
struct S3
{
char c[6];
char d[6];
};
int main(int argc, char *argv[])
{
struct S2 s2;
printf ("SIZE int = %d\n",sizeof(int));
printf ("SIZE S1 = %d\n",sizeof(struct S1));
printf ("SIZE S2 = %d\n",sizeof(struct S2));
printf ("SIZE S3 = %d\n",sizeof(struct S3));
printf ("SIZE s2 = %d\n",sizeof(s2));
printf ("SIZE s2.a = %d\n",sizeof(s2.a));
printf ("SIZE s2.b = %d\n",sizeof(s2.b));
}
//----------------END TEST PROGRAM----------------
The output is what follows:
SIZE int = 4
SIZE S1 = 6
SIZE S2 = 12
SIZE S3 = 12
SIZE s2 = 12
SIZE s2.a = 6
SIZE s2.b = 4
As you can see, size of structure S2 is just pointless..... please can
anyone tell me what is going on?
Claudio
More information about the Gcc-help
mailing list