static union { char c; unsigned long l; } endian_test = { { 'l', '?', '?', 'b' } };#define ENDIANNESS ((char)endian_test.l)(如果ENDIANNESS=’l’表示系统为little endian,为’b’表示big endian )。提供一个简洁的判断程序:#include　　int main(int argc,char* argv[])　　{　　using std::cout;　　int number = 1;　　if(*(char *)&number)　　cout<<"Little-endian!\n";　　else　　cout<<"Big-endian!\n";　　return 0;　　}int checkCPU() {union w { int a; char b; } c;c.a = 1;return (c.b == 1);/* 1 : little-endian *//* 0 : big-endian */}2011年8月27日17:38:15 添加测试大小端l#includeint main(void){inta = 0x12345678;unsignedchar *p=(unsigned char *)&a;if(0x78==*p){printf("littleend\n");}else{printf("bigend\n");}return0;}运行环境:Linuxroot-desktop 2.6.32-24-generic #39-Ubuntu SMP Wed Jul 28 06:07:29 UTC 2010 i686 GNU/Linux/