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]

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


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