struct B{ char a; int b; unsignedshort c; long d; unsignedlonglong e; char f; }__attribute__((aligned));
struct C{ char a; int b; unsignedshort c; long d; unsignedlonglong e; char f; }__attribute__((aligned(1)));
struct D{ char a; int b; unsignedshort c; long d; unsignedlonglong e; char f; }__attribute__((aligned(4)));
struct E{ char a; int b; unsignedshort c; long d; unsignedlonglong e; char f; }__attribute__((aligned(8)));
struct F{ char a; int b; unsignedshort c; long d; unsignedlonglong e; char f; }__attribute__((packed));
int main(int argc,char**argv){ printf("A = %d, B = %d, C = %d, D = %d, E = %d, F = %d\n", sizeof(struct A),sizeof(struct B),sizeof(struct C),sizeof(struct D),sizeof(struct E),sizeof(struct F)); return 0; }
在一个 32位机 上运行结果如下:
[Copy to clipboard] [ - ]CODE: [root@Kendo develop]# gcc -o align align.c [root@Kendo develop]# ./align A = 28, B = 32, C = 28, D = 28, E = 32, F = 20 [root@Kendo develop]#