字节序
#include<stdio.h> #include<cstdlib> int main() { union { short s; char c[sizeof(s)]; }un; un.s = 0x0102; if (sizeof(short) == 2) { if (un.c[0] == 1 && un.c[1] == 2) { printf("big-endina\n"); } else if (un.c[1] == 1 && un.c[0] == 2) { printf("small-endina\n"); } else { printf("unknown\n"); } } else { printf("sizeof(short) = %d\n", sizeof(short)); } return 0; }