64,649
社区成员
发帖
与我相关
我的任务
分享
union a
{
int a_int1;
double a_double;
int a_int2;
};
typedef struct
{
a a1;
char y;
} b;
class c
{
double c_double;
b b1;
a a2;
};
sizeof(c)=8+16+8 会有什么问题?
系统的默认对齐数值就是8,没有多余的字节需要填充,自然就是32
加入预编译条件#pragma pack(4)按4字节对齐
sizeof(c)=8+12+8
union a
{
int a_int1;
double a_double;
int a_int2;
};
typedef struct
{
a a1;
char y;
} b;
class c
{
// char ss;
double c_double;
b b1;
a a2;
};
int main()
{
a wu;
b wu1;
c wu2;
cout << sizeof(wu)<<endl;
cout << sizeof(wu1)<<endl;
cout << sizeof(wu2)<<endl;
system("pause");
}