###### 一个牛X的例子来计算结构体的sizeof
0 4 8
0 4 8
0 4 6
sizeof(E) = 16
sizeof(F) = 16
sizeof(T) = 14
sizeof(struct_taga) = 4
sizeof(struct_tagb) = 3
sizeof(struct_tagc) = 4

--------------
#include <stddef.h>
#include <stdio.h>

//package size defaults to 8
struct E
{
int i;   // size 4
short j;   // size 2
double k;   // size 8
};

#pragma pack(4)
struct F
{
int i;
short j;
double k;
};

#pragma pack(2)
struct T
{
int i;
short j;
double k;
};

struct struct_taga
{
char i;
short j;
};

#pragma pack(push, r2, 1)
struct struct_tagb
{
char i;
short j;
};

#pragma pack(push, 8)
struct struct_tagc
{
char i;
short j;
};

void main()
{
printf("%d ", offsetof(E, i));
printf("%d ", offsetof(E, j));
printf("%d\n", offsetof(E, k));
printf("%d ", offsetof(F, i));
printf("%d ", offsetof(F, j));
printf("%d\n", offsetof(F, k));
printf("%d ", offsetof(T, i));
printf("%d ", offsetof(T, j));
printf("%d\n", offsetof(T, k));

printf("sizeof(E) = %d\n", sizeof(E));
printf("sizeof(F) = %d\n", sizeof(F));
printf("sizeof(T) = %d\n", sizeof(T));

printf("sizeof(struct_taga) = %d\n", sizeof(struct_taga));
printf("sizeof(struct_tagb) = %d\n", sizeof(struct_tagb));
printf("sizeof(struct_tagc) = %d\n", sizeof(struct_tagc));
}

#### c/c++中使用sizeof计算结构体struct和类class的长度(字节)

2016-03-24 09:44:10

#### sizeof&结构体、共同体大小的计算方法笔记

2013-11-12 21:51:37

#### sizeof计算结构体大小（字节对齐）

2016-04-03 15:06:31

#### C++中的结构体与sizeof

2007-04-09 22:33:00

#### sizeof()计算数组结构体类大小长度

2015-06-27 14:13:07

#### sizeof求结构体大小的问题

2016-03-09 10:37:13

#### sizeof求结构体大小问题详解

2016-04-22 14:21:08

#### 对结构体进行sizeof计算要点！！！不同编译器结果不一样，gcc宇VC就不一样

2013-03-05 23:50:35

#### C语言sizeof求结构体大小问题汇总

2015-07-05 21:13:23

#### c语言sizeof求结构体的大小

2015-09-01 19:39:03