Created
April 20, 2014 02:11
-
-
Save icsaas/11103123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
main() | |
{ | |
struct A { | |
int a; | |
char b; | |
short c; | |
}; | |
struct B { | |
char b; | |
int a; | |
short c; | |
}; | |
#pragma pack(2) /*指定按2字节对齐*/ | |
struct C { | |
char b; | |
int a; | |
short c; | |
}; | |
#pragma pack() /*取消指定对齐,恢复缺省对齐*/ | |
#pragma pack(1) /*指定按1字节对齐 */ | |
struct D { | |
char b; | |
int a; | |
short c; | |
}; | |
#pragma pack() /*取消指定对齐,恢复缺省对齐 */ | |
int s1=sizeof(struct A); | |
int s2=sizeof(struct B); | |
int s3=sizeof(struct C); | |
int s4=sizeof(struct D); | |
printf("%d\n",s1); | |
printf("%d\n",s2); | |
printf("%d\n",s3); | |
printf("%d\n",s4); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 | |
12 | |
8 | |
7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment