typedef struct A
{
WORD m1;
WORD m2;
LONGLONG n1;
LONGLONG n2;
LONGLONG n3;
DWORD x;
}a;
然后,sizeof(A),等于多少?
40!!
WORD是2,DWORD是4,LONGLONG是8
2+2+8+8+8+4 = 32呀?怎么会是40?
原来是VC编译器的问题,project/setting中设置C++编译选项,将struct member alignment从默认的8 bytes设为1 byte,就好了。
...
可是,编译出现了很多warning,怎么办呢?可以用
#pragma pack(push,1)
typedef struct A
{
...
};
#pragma pack(pop)