1. #pragma pack(show) 可以查看当前设置
2. #pragma pack(n) 作用于结构体时。a: 每个成员.xxx的起始位置要是min(sizeof(.xxx), n)的倍数。b: 结构体大小要是min(max(sizeof(.xxx)), n)的倍数
3. 结构体成员是数组时:比如下面,AA的size是15,BB的size是24
struct AA { char one; char two[2]; char eight[8]; char four[4]; }; struct BB { char one; short two; double eight; int four; };
4. 存在结构体成员时,该成员的起始位置要是min(n, max(sizeof(.xxx)))的倍数。
5. #pragma pack(n)和__declspec(align(m))同时存在时:a. 每个结构体成员.xxx的起始位置要是min(sizeof(.xxx), n, m)的倍数。b. 结构体大小要是max(max(sizeof(.xxx)), m)的倍数,与n无关。
------------------------------------------------------------------------------------------------------------------------------------
总结成一句话:The sizeof value for any structure is the offset of the final member, plus that member's size, rounded up to the nearest multiple of the largest member alignment value or the whole structure alignment value, whichever is greater.