Linux Cワンストップ学習問題の答え19.4
596 ワード
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
",
test.a[0], test.a[1], test.a[2], test.a[3]);
if (test.a[0] == 0x11) {
printf("The tested platform is Little Endian.
");
} else if (test.a[0] == 0x44) {
printf("The tested platform is Big Endian.
");
} else {
printf("The tested platform is perverted. Destory it!
");
}
return 0;
}