Bitfields in C with struct containing union of structs
问题 Hm... why is it that, when I print sizeof(struct MyStruct) , it outputs 3 (instead of 2) for this code? #pragma pack(push, 1) struct MyStruct { unsigned char a : 6; union { struct { unsigned int b : 9; }; }; }; #pragma pack(pop) In case it matters, I'm running MinGW GCC 4.5.0 on Windows 7 x64, but honestly, the result is weird enough for me that I don't think the compiler and the OS matter too much here. :\ 回答1: You can't have the field starting at an address that is not byte aligned. You're