BTW: this works on GCC. That is, it prints 2. (Care to test it on MSVC?)
Code:
#ifdef _MSC_VER
#pragma pack(push, r1, 1)
#endif
struct data
{
char one, two;
}
#ifdef __GNUC__
__attribute__((__packed__));
#elif defined(_MSC_VER)
#pragma pack(pop, r1)
#else
#error "Cannot eliminate structure padding"
#endif
;
#include <stdio.h>
int main() {
printf("%d\n", (int)sizeof(struct data));
return 0;
}
Note how I had to change the GCC line:
Code:
__attribute__((__packed__));
attribute and double underscores surrounding packed.
[edit] It's kind of funny how many times that buggy code was copy-and-pasted without anyone actually reading it . . . . [edit]