用共用体来实现计算机的大小端;
1 #include<string.h>
2 #include<stdlib.h>
3 #include<stdio.h>
4 int main(int argc, const char *argv[])
5 {
6 typedef union node
7 {
8 char a;
9 int b;
10 }small;
11 printf("size = %ld\n",sizeof(union node));
12 small buf;
13 buf.b =0x87654321;
14 if(buf.a == 0x21)
15 {
16 printf("a = %#x\tsmall\n",buf.a);
17 }
18 else if(buf.a == 0x87)
19 {
20 printf("a = %#x\tbig\n",buf.a);
21 }
22
23 return 0;
24 }