The following code produces different output in gcc4.0.0 and MSVC++7 .NET. Additionally, I've tried 3.4.3 20050227 (Red Hat 3.4.3-22.fc3) and gcc 3.3.4 20040817 (Red Hat Linux 3.3.4-2), who all produce the same output as gcc4.0.0.
I'm unsure who is right here (don't know the exact C++ standards). If gcc4 is right and MSVC++ is wrong this bug is invalid. CODE: #include <stdio.h> #define DEFSTR(name) \ typedef struct name { \ unsigned int var : 13; \ }; #pragma pack(push, 1) DEFSTR(pack1_struct) #pragma pack(pop) #pragma pack(push, 2) DEFSTR(pack2_struct) #pragma pack(pop) #pragma pack(push, 4) DEFSTR(pack4_struct) #pragma pack(pop) #pragma pack(push, 8) DEFSTR(pack8_struct) #pragma pack(pop) #pragma pack(push, 16) DEFSTR(pack16_struct) #pragma pack(pop) DEFSTR(unpacked_struct) int main( int argc, char** argv ) { printf("sizeof(pack1_struct) = %u\n", sizeof(pack1_struct) ); printf("sizeof(pack2_struct) = %u\n", sizeof(pack2_struct) ); printf("sizeof(pack4_struct) = %u\n", sizeof(pack4_struct) ); printf("sizeof(pack8_struct) = %u\n", sizeof(pack8_struct) ); printf("sizeof(pack16_struct) = %u\n", sizeof(pack16_struct) ); printf("sizeof(unpacked_struct) = %u\n", sizeof(unpacked_struct) ); return 0; } PRODUCES ON GCC: sizeof(pack1_struct) = 2 sizeof(pack2_struct) = 2 sizeof(pack4_struct) = 4 sizeof(pack8_struct) = 4 sizeof(pack16_struct) = 4 sizeof(unpacked_struct) = 4 PRODUCES ON MSVC++7: sizeof(pack1_struct) = 4 sizeof(pack2_struct) = 4 sizeof(pack4_struct) = 4 sizeof(pack8_struct) = 4 sizeof(pack16_struct) = 4 sizeof(unpacked_struct) = 4 -- Summary: sizeof() packed structs potential errors Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: moudekotte at khaeon dot nl CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: i686-redhat-linux GCC target triplet: i386-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21361