1、编写一个程序,测试运行它的平台是大端还是小端字节序。
#include <stdio.h>
union test_type {
int i;
char a[4];
};
int main(void)
{
union test_type test = {0x44332211};
printf("hex dump of u: %x %x %x %x\n",
test.a[0], test.a[1], test.a[2], test.a[3]);
if (test.a[0] == 0x11) {
printf("The tested platform is Little Endian.\n");
} else if (test.a[0] == 0x44) {
printf("The tested platform is Big Endian.\n");
} else {
printf("The tested platform is perverted. Destory it!\n");
}
return 0;
}