方式一

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

方式二

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

 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 }

 

相关文章:

  • 2022-12-23
  • 2021-06-22
  • 2021-09-07
  • 2021-06-10
  • 2022-12-23
  • 2021-07-02
猜你喜欢
  • 2021-05-27
  • 2021-10-25
  • 2022-12-23
  • 2021-08-31
  • 2022-02-19
  • 2022-12-23
  • 2021-09-28
相关资源
相似解决方案