This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
sizeof and allignment on 32bit target
- From: "Eric de Jong" <list_ericdejong_10 at gmx dot net>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Fri, 25 Jul 2003 10:13:30 +0200
- Subject: sizeof and allignment on 32bit target
Hello,
Who can tell me why sizeof(Test.Value) gives 12 bytes? I expected 10 bytes.
Due to allignment in my 32bit target (both intel and arm) two bytes are added
before 'Value4', and sizeof(TestStruct) is 16bytes
Here is my test program:
test.cpp:
--------
#include "stdio.h"
int main()
{
struct TestStruct
{
struct
{
unsigned long Value1;
unsigned long Value2;
unsigned short Value3;
} Value;
unsigned long Value4;
} Test;
printf("\r\n" "Sizeof Test: %d", sizeof(Test));
printf("\r\n" "Sizeof Value: %d", sizeof(Test.Value));
printf("\r\n" "Expected size of Value: 10");
}
----------
target:
intel P3, gcc 3.2 20020927 (prerelease)
- the target was build under cygwin: 'gcc test.cpp' and tested: './a.exe'.
result:
-----------
$ ./a.exe
Sizeof Test: 16
Sizeof Value: 12
Expected size of Value: 10
-----------
On my ARM target (gcc 3.3) I detected the same problem.
Eric