我是靠谱客的博主 爱撒娇方盒,这篇文章主要介绍大小尾端数据测试,现在分享给大家,希望可以做个参考。

参考自《程序员面试攻略》

一般也就想到

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。

最后

以上就是爱撒娇方盒最近收集整理的关于大小尾端数据测试的全部内容,更多相关大小尾端数据测试内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(118)

评论列表共有 0 条评论

立即
投稿
返回
顶部