http://blog.csdn.net/ce123_zhouwei/article/details/6971544


一个小程序判断机器的大小端

  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.     union {
  5.         int s;
  6.         char c[sizeof(int)];
  7.     }un;
  8.     un.s = 0x12345678;
  9.     
  10.     printf("%p,%p,%p,%p\n",un.c[0],un.c[1],un.c[2],un.c[3]);
  11.     printf("%p,%p,%p,%p\n",&un.c[0],&un.c[1],&un.c[2],&un.c[3]);
  12. # if __BYTE_ORDER == __LITTLE_ENDIAN
  13.     printf("little endian\n");
  14. # elif __BYTE_ORDER == __BIG_ENDIAN
  15.     printf("big endian\n");
  16. # else
  17.     # error "__BYTE_ORDER neither __LITTLE_ENDIAN nor __BIG_ENDIAN!!!"
  18. # endif
  19.     return 0;
  20. }    
10-16 07:50
查看更多