先算内结构体的大小,在以外数据类型最大的数据大小对齐,然后加上其他数据对齐后的大小。
比如以下代码。
#include <stdio.h>
typedef struct _s
{
int a;
short b;
char buf[11];
long long c;
}ST;
typedef struct _c
{
char num[13];
int x;
struct _s data[3];
}CT;
int main(int argc,char *argv[])
{
printf("ST:%d,CT:%d\n",sizeof(ST),sizeof(CT));
}