考虑以下:
class A { public:
int gate_type : 4;
bool storage_elem : 1;
uint8_t privilege : 2;
bool present : 1;
} __attribute__((packed));
class B { public:
struct Sub {
int gate_type : 4;
bool storage_elem : 1;
uint8_t privilege : 2;
bool present : 1;
} type_attr; //Also tried with "__attribute__((packed))" here in addition to outside
} __attribute__((packed));
编译器是 g++ 4.8.1。大小(A)==1,大小(B)==4。为什么会这样?我需要结构 B 之类的大小为 1 的东西。