sizeof and allignment on 32bit target

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux