利用union类型测试机器是大端还是小端(Big_endian or Little_endian)

#include<stdio.h>
int check_sys()
{
 union check
 {
  int i;
  char ch;
    }c;
 c.i = 1;
 return (c.ch == 1);
}
int main()
{
 int ret = check_sys();
 if (ret == 1)
  printf("Little_endian\n");
 else
  printf("Big_endian\n");
 system("pause");
 return 0;
}

你可能感兴趣的:(UNION,大端,小端)