检测本地字节序 是大端存储还是小端存储
#include <stdio.h> typedef union{ unsigned short value; unsigned char byte[2]; }CodeOrderUnion; void test_endian() { CodeOrderUnion order; order.value = 0x0102; if(order.byte[0] == 0x01 && order.byte[1] == 0x02){ printf("Small Endian\n"); } else if(order.byte[0] == 0x02 && order.byte[1] == 0x01){ printf("Big Endian\n"); } else{ printf("error!\n"); } } int main() { test_endian(); }