#include<stdio.h>#define SIZE(a) (sizeof(a))
union
{/* data */short s;char c[SIZE(short)];short b;int d;char f;
}un;
int main(int argc,char **argv)
{un.s = 0x0102;if(SIZE(short) == 2)//表示short是16位{printf("===\n");printf("c[0] = %d,c[1] = %d\n",un.c[0],un.c[1]);if(un.c[0] == 1 && un.c[1] == 2)printf("this is big-endian\n");elseprintf("this is little-endian\n");printf("un.b = %d\n",un.b);printf("sizeof(un) = %ld\n",SIZE(un));}else{printf("--\n");} return 0;
}