字节序判断:
#include <stdio.h>
union test
{
char ch;// 0x78
int num;// 0x12 34 56 78
};
int main(int argc, char const *argv[])
{
union test t;
t.num = 0x12345678;
if(0x78 == t.ch)
{
printf("small endian.\n");
}
else
{
printf("big endian.\n");
}
return 0;
}