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]

Re: alignment/padding of structures


At 17.34 24/01/2002 (GMT +0100), Frederic Christen wrote:
>I've a problem in understanding the behaviour of
>alignment and padding between MSVC++ and gcc-2.9.95 (Linux).

I guess you mean gcc 2.95.x ...


>example:
>
>struct foo {
>         double a;
>         double b;
>         float c;
>};
>
>with MSVC++ and #pragma pack(4) set : sizeof(foo) = 20
>with MSVC++ and #pragma pack(8) set : sizeof(foo) = 24
>(the alternative Zp'x' flag causes the same effect)
>
>but with gcc there is no effect of the #pragma:
>with gcc and #pragma pack(4) set : sizeof(foo) = 20
>with gcc and #pragma pack(8) set : sizeof(foo) = 20

#pragma are compiler dependent.
I don't know whether gcc has a way to allign ALL your variables to a 
certain minimum amount.
For single variable and struct members, you can use the "aligned" attrbiute 
to set the minimum alignment, like this:

struct foo {
         double a __attribute__ ((aligned (8)));
         double b __attribute__ ((aligned (8)));
         float c __attribute__ ((aligned (8)));
}

This will make the 3 fields 8-byte allignd.


>Which compiler-flag has to be set to get the same alignment/
>padding as with MSVC++ ?

Don't know if exist something like this. You can check on the manual.

HTH
fwyzard


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