参考自《程序员面试攻略》
一般也就想到
bool endianess(){
int testNum=1;
char *ptr=(char *)&testNum;
return (*ptr);
}
作者提出用union的方法好聪明!
bool endianess(){
union{
int theInteger;
char singleByte;
}endianTest;
endianTest.theInteger=1;
return endianTest.singleByte;
return (*ptr);
}
union还可以这样用,膜拜。
其实几乎一般都不用union。