判断机器大小端的两种实现方式

方式一

  使用两个静态字节,代码较长

方式二

  使用三个静态字节,代码简短

 1 bool is_big_endian1(){
 2     static union tmp_u{
 3         tmp_u():s(0x0100){}
 4         short s;
 5         char b;
 6     } tmp;
 7 
 8     return tmp.b;
 9 }
10 
11 bool is_big_endian2(){
12     static short s = 0x0100;
13     static char b = (*(char*)&s);
14 
15     return b;
16 }
原文地址:https://www.cnblogs.com/woxinfeixiang2015/p/15614287.html