http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991
--- Comment #6 from daniel.c.klauer at web dot de 2012-10-06 23:02:22 UTC --- Using the ms_struct attribute instead of compiling with -mms-bitfields reproduces the packing issue, while using the gcc_struct attribute prevents the issue from showing up even under -mms-bitfields. These struct examples show the packing issue without nested structs: struct __attribute__((ms_struct, packed)) A { int a; short b; }; struct __attribute__((ms_struct, packed)) B { short a; int b; }; sizeof(struct A) == 6 as expected sizeof(struct B) == 8 unexpected, expected 6 instead offsetof(struct B, b) == 4 unexpected, expected 2 instead A message [1] from the mingw-w64-public mailing list indicates this behaviour: Only the outer struct is packed, causing padding bytes at its end to be removed as expected, but not the fields: padding bytes in front of a field according to the field's natural alignment are not removed, despite the packed attribute, which is unexpected. Explicitly packing the fields does not help: struct __attribute__((ms_struct)) C { int a __attribute__((packed, aligned(1))); short b __attribute__((packed, aligned(1))); }; struct __attribute__((ms_struct)) D { short a __attribute__((packed, aligned(1))); int b __attribute__((packed, aligned(1))); }; sizeof(struct C) == 6 as expected sizeof(struct D) == 8 unexpected, expected 6 instead offsetof(struct D, b) == 4 unexpected, expected 2 instead [1] http://sourceforge.net/mailarchive/message.php?msg_id=29650589