G++ structure member alignment

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

 



Hi,

A quite obvious problem of structure member alignment. I am porting to
Linux some Windows legacy code which created with assumption that that
no padding is performed on structures. In other words if we define

struct t_struct
{
       char ch1;
       short s1;
} t1;

and

typedef t_struct my_var;

then

sizeof(my_var) will be "3" on Intel 586 platform.

Compiling similar code with gcc  3.4.3 on Linux generates variable
sized as 4 bytes.

"Man g++" includes lot of alignment options: for labels, for function,
for jumps and so on but none of them looks to take care about
structures ...

Here is a full code for test program:

#include <stdio.h>

struct t_struct
{
       char l;
       short s1;
} t1_struct;

typedef t_struct my_str;

int main()
{
       my_str my;
       printf("Size if %d\n",sizeof(my));
       return 0;
}

Thank you in advance.

[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