标签:packing
Data Structure Alignment 2#include <stdio.h> struct A{ int a; short b; int c; char d; }; struct B1{ double a; short b; int c; char d; }; #pragma pack(push,8) struct B2{ double a; short b; int c; char d; }; #pragma pack(pop) #pragma pack(push,4) struct B3{ double a; short b; int c; char d; }; #pragma pack(pop) #pragma pack(push,1) struct B4{ double a; short b; int c; char d; }; #pragma pack(pop) struct C{ int a; short b[2]; char c[2]; }; int main(){ printf("A: %d\n", sizeof(struct A)); printf("B1: %d\n", sizeof(struct B1)); printf("B2: %d\n", sizeof(struct B2)); printf("B3: %d\n", sizeof(struct B3)); printf("B4: %d\n", sizeof(struct B4)); printf("C: %d\n", sizeof(struct C)); return 0; }运行结果:
For 32-bit x86:
标签:packing
原文地址:http://blog.csdn.net/vonzhoufz/article/details/44940599