标签:
大小端的定义无需赘言,常用的方法有使用联合体和指针法,如:
int checkCPU() { union w { int a; char b; }c; c.a = 1; return (c.b == 1); // 小端返回TRUE,大端返回FALSE }
实际上Linux操作系统的源码中,其判断更为简洁:
static union { char c[4]; unsigned long mylong; } endian_test = {{ ‘l‘, ‘?‘, ‘?‘, ‘b‘ } }; #define ENDIANNESS ((char)endian_test.mylong)
标签:
原文地址:http://www.cnblogs.com/yves/p/5950677.html