sizeof struct { short x } on arm gcc-3.2.1

Rutger Hofman rutger@cs.vu.nl
Fri Feb 16 15:13:00 GMT 2007


Hello list,

I did a quick search in the archives but I found nothing appropriate.

My (embedded) development system is gcc-3.2.1 arm-elf. I don't really 
understand its value for sizeof(struct { short x }).

Given the following program:

<code>
#include <stdio.h>

int
main(int argc, char *argv[])
{
     struct {
         short           s;
     } s_sh;

     printf("sizeof s_sh %d\n", (int) sizeof s_sh);
     printf("sizeof short %d\n", (int) sizeof(short));

     return 0;
}
</code>

it prints:

sizeof s_sh 4
sizeof short 2

Why isn't the size of this struct also 2? I assume this is to do with 
alignment, but even then I don't really understand. To create an array 
of such structs, no padding seems required.

Or has this already been fixed in not so ancient versions of arm-elf-gcc?

Thanks for enlightening me,

Rutger Hofman
VU Amsterdam



More information about the Gcc mailing list