我们知道机器的CPU分为大端和小端,但是如何通过程序区判断呢?这里给出一个常用的,比较好用的办法,先看程序:
/************************************************************************* > File Name: HostOrder.c > Author: Baniel Gao > Mail: createchance@163.com > Blog: blog.csdn.net/createchance > Created Time: Tue 08 Apr 2014 08:39:23 PM CST ************************************************************************/ #include <stdio.h> int main(void) { union { int a; char b; } test; test.a = 1; if (test.b == 1) printf("Your host is little-endian! \n"); else printf("Your host is big-endian! \n"); }
原文:http://blog.csdn.net/createchance/article/details/23206561