字节对齐
#pragma pack(4)
typedef struct Test
{
short a;//2+2
struct t
{
int b;//4
double c;//8
char d;//1+3
}tt;
long e;//4
}TEST;
void main()
{
cout<<sizeof(Test)<<endl;//24
}
#pragma pack(4)
typedef struct Test
{
short a;//2+2
struct t
{
int b;//0
double c;//0
char d;//0
};
long e;//4
}TEST;
void main()
{
cout<<sizeof(Test)<<endl;//8
}
由于嵌套的struct t没有给出对象,所以没有开辟空间