如果有Pack 对齐规则= min(pack(),sizoef(elementsize))
#pragma pack(2)
struct TestStruct {
short int aa;
char bb;
};
size 为3
如果pack(1)那就是4
位域:
struct TestMtstruct {
unsigned aa : 17;
unsigned bb : 11;
unsigned cc : 15;
unsigned dd : 19;
unsigned ee : 11;
double ff;
};
默认4字节对齐:17+11 <32 4.15 <32 =4 19+11 <32 =4 Double ff =8
4+4+4+(4) +8 = 24
但是如果是#pragma pack(2)呢?就不用补了:直接4+4+4+8 =20