http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991

--- Comment #5 from Mikael Pettersson <mikpe at it dot uu.se> 2012-08-22 
08:34:46 UTC ---
The following variation of the test case was compiled with both gcc-4.7.1 and
MS Visual Studio 2008:

#include <stdio.h>

#if defined(__GNUC__)
struct A1 {
    short s;
    struct { int i; } x;
} __attribute__((__packed__));
#endif

#pragma pack(1)
struct A2 {
    short s;
    struct { int i; } x;
};
#pragma pack()

int main(void)
{
#if defined(__GNUC__)
    printf("sizeof(struct A1) == %u\n", (unsigned)sizeof(struct A1));
#endif
    printf("sizeof(struct A2) == %u\n", (unsigned)sizeof(struct A2));
    return 0;
}

Note that structs A1 and A2 are identical, except A1 is packed (when compiled
by gcc) using the attribute syntax and A2 is packed using the #pragma syntax.

Compiling this with gcc-4.7.1 (target x86_64-w64-mingw32) with -mms-bitfields
(which is the default) gives:

sizeof(struct A1) == 8
sizeof(struct A2) == 6

proving that attribute packed doesn't work.  With -mno-ms-bitfields both
structs are reported as being 6 bytes.

Compiling with Visual Studio 2008 gives:

sizeof(struct A2) == 6

as expected.

Reply via email to