先看一段代码,巧妙的得出大端或小端:
static union { char c[4]; unsigned long mylong; } endian_test = {{ 'l', '?', '?', 'b' } };#define ENDIANNESS ((char)endian_test.mylong)
如果ENDIANNESS=’l’表示系统为little endian,为’b’表示big endian