C++中有个pragma pack 会对对齐方式进行改变
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
#pragma pack(push) //保存对齐状态
#pragma pack(4)//设定为4字节对齐
struct TEST0
{
char m1;
double m4;
int m3;
};
#pragma pack(pop)//恢复对齐状态
#pragma pack(push)
#pragma pack(2)<span style="white-space:pre">   </span>//#pragma pack(1)会有不同的结果
struct TEST1    //12
{
char a;
int b;
char c;
};
#pragma pack(pop)
struct TEST2    //8
{
char a;
char b;
int c;
};
struct TEST3    //8
{
char a;
char b;
char c;
int d;
};
struct TEST4    //12
{
char a[5];
int b;
};
struct TEST5    //8 + 8 + 8 = 24
{
double a; //8
char b; //4
int c; //4,location the b memery
char d[5]; //5
};
int _tmain(int argc, _TCHAR* argv[])
{
struct TEST0 t0;
cout << sizeof(t0) << endl;
struct TEST1 t1;
struct TEST2 t2;
struct TEST3 t3;
struct TEST4 t4;
struct TEST5 t5;
cout << sizeof(t1) << endl << sizeof(t2) << endl;
cout << sizeof(t3) << endl << sizeof(t4) << endl << sizeof(t5) << endl;
return 0;
}
  可以简单这样理解 要么按照默认对齐,要么按照pack里面的数值进行对齐
  对TEST1 pack里面值为1与2会有不同结构
  当为1时,占用6个字节
  a b1 b2 b3
  b4 c
  当为2时, 占用8个字节
  a ax b1 b2
  b3 b4 c cx