sizeof and allignment on 32bit target

Eric de Jong list_ericdejong_10@gmx.net
Fri Jul 25 10:45:00 GMT 2003


Thank you, Jan Zizka, Roman Kellner

I would expect that the allignment has only influence on the address of
variables, not on the total size of a structure. It looks like the compiler
calculates the size of the structure to be a multiple of the largest item in the
structure.
What I want is to allign each variable in the structure to it's own size, but
the total size of the structure to be the actual size. Is this possible?

Eric

----
  struct { unsigned char Value2; unsigned char Value3; unsigned char Value4; }
Value;
  sizeof(Value) = 3;

  struct { unsigned short Value1; unsigned char Value2; unsigned char Value3;
unsigned char Value4; } Value;
  sizeof(Value) = 6; (not 5)

  struct { unsigned long Value1; unsigned char Value2; unsigned char Value3;
unsigned char Value4; } Value;
  sizeof(Value) = 8; (not 7)




More information about the Gcc-help mailing list