sizeof and allignment on 32bit target

Jan Zizka ziza@klubicko.net
Fri Jul 25 08:34:00 GMT 2003


Hi,

On Fri, Jul 25, 2003 at 10:13:30AM +0200, Eric de Jong wrote:
>    struct TestStruct
>    {
>       struct
>       {
>          unsigned long Value1;
>          unsigned long Value2;
>          unsigned short Value3;
>       } Value;
>       unsigned long Value4;
>    } Test;

if you should get those 10 you have to add packed attribute to the struct
definition:

    struct TestStruct
    {
       struct
       {
          unsigned long Value1;
          unsigned long Value2;
          unsigned short Value3;
       } Value __attribute__ ((packed));
       unsigned long Value4;
    } Test __attribute__ ((packed));

otherwise the alignment will be always 4 bytes for any structure.

-ziza




More information about the Gcc-help mailing list