结构体内存对齐

238 阅读1分钟

020ED4A3-FB62-4F00-8231-86AD5F1A0B6E.png struct LGStruct1 {

double a;       // 8    [0 7]
char b;         // 1    [8]
int c;          // 4    (9 10 11 [12 13 14 15]
short d;        // 2    [16 17] 24

}struct1;

struct LGStruct2 {

double a;       // 8    [0 7]
int b;          // 4    [8 9 10 11]
char c;         // 1    [12]
short d;        // 2    (13 [14 15] 16

}struct2;

struct LGStruct3 {

double a;   //8 [0 7]
int b;      //4 [8 9 10 11]
char c;     //1 [12]
short d;    //2 (13 [14 15]
int e;      //4 [16 17 18 19]
struct LGStruct1 str; //24 (20 21 22 23 [24 48] 48
                      //[24 48] 具体为[24 31][32](33 34 35 [36 39][40 41] 42..48)

}struct3;