23,217
社区成员




union D
{
char a[5];
int b;
};
struct test_t {
int a;
char b;
char c[10];
D d;
short e;
};
union D
{
char a[5];
int b;
/* padding 3 bytes, 使unin的总长度为 4bytes*2倍=8bytes */
};
struct test_t
{
int a; /* 4 bytes, 注意,默认是4bytes对齐 */
char b; /* 1 bytes */
char c[10]; /* 10 bytes */
/* padding 3 bytes, 例D的开始偏移地址为 15+1=16 bytes */
union D d; /* 8 bytes */
short e; /* 2 bytes, padding 8 bytes, 才能使 test_t的总体大小符合 10的整数倍,即(26+2bytes节填充长度)=28bytes */
/* 编译器自动在此处填充2bytes, 注意到此结构体的最大基本类型是int型,即结构体的总长度是int型长度的整数度 */
};