This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GCC 2.96 shows bogus memory allocation when allocating some givenstructs?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]