使用c语言判断该本地机器的字节序(byte order)

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int x = 1;
 5     if(*(char*)&x == 1){
 6         printf("normal order\n");
 7     }
 8     else{
 9         printf("not normal order, maybe powerpc\n");
10     }
11 
12 
13 }

参考资料:Linux Kernel Development(Third Edition)书后末尾章节
以上在Ubuntu的笔记本电脑上测试通过,显示为正常字节序。

 

posted @ 2019-01-09 23:43  panrui  阅读(930)  评论(0编辑  收藏  举报