/************************************************************************************ ** File: - Z:\code\c\Alignment\Align.c ** ** Copyright (C), Long.Luo, All Rights Reserved! ** ** Description: ** Align.c --- To learn the details of Alignment by the compiler. ** ** Version: 1.1 ** Date created: 22:33:50,10/12/2012 ** Author: Long.Luo ** ** --------------------------- Revision History: -------------------------------- ** <author> <data> <desc> ** ************************************************************************************/ #include <stdio.h> struct ALIGN2 { char mA; int mB; short mC; }; struct ALIGN3 { int mB; char mA; short mC; }; int main(void) { struct ALIGN2 aln2; struct ALIGN3 aln3; printf("The size of struct ALIGN2 is: %d\n", sizeof(aln2)); printf("\t aln2.mA=0x%x, aln2.mB=0x%x, aln2.mC=0x%x\n", &aln2.mA, &aln2.mB, &aln2.mC); printf("The size of struct ALIGN3 is: %d\n", sizeof(aln3)); printf("\t aln3.mA=0x%x, aln3.mB=0x%x, aln3.mC=0x%x\n", &aln3.mA, &aln3.mB, &aln3.mC); return 0; }
输出文件的后缀为:*.cpp 文件。
.file "Align.c" .section .rodata .align 4
/************************************************************************************ ** File: - Z:\code\c\Alignment\AlignPackOne.c ** ** Copyright (C), Long.Luo, All Rights Reserved! ** ** Description: ** Align.c --- To learn the details of Alignment by the compiler. ** ** Version: 1.1 ** Date created: 23:39:05,10/12/2012 ** Author: Long.Luo ** ** --------------------------- Revision History: -------------------------------- ** <author> <data> <desc> ** ************************************************************************************/ #include <stdio.h> #pragma pack(1) struct ALIGN2 { char mA; int mB; short mC; }; struct ALIGN3 { int mB; char mA; short mC; }; int main(void) { struct ALIGN2 aln2; struct ALIGN3 aln3; printf("The size of struct ALIGN2 is: %d\n", sizeof(aln2)); printf("\t aln2.mA=0x%x, aln2.mB=0x%x, aln2.mC=0x%x\n", &aln2.mA, &aln2.mB, &aln2.mC); printf("The size of struct ALIGN3 is: %d\n", sizeof(aln3)); printf("\t aln3.mA=0x%x, aln3.mB=0x%x, aln3.mC=0x%x\n", &aln3.mA, &aln3.mB, &aln3.mC); return 0; }