C Macro definition to determine big endian or little endian machine?
问题 Is there a one line macro definition to determine the endianness of the machine. I am using the following code but converting it to macro would be too long. unsigned char test_endian( void ) { int test_var = 1; unsigned char test_endian* = (unsigned char*)&test_var; return (test_endian[0] == NULL); } 回答1: Code supporting arbitrary byte orders, ready to be put into a file called order32.h : #ifndef ORDER32_H #define ORDER32_H #include <limits.h> #include <stdint.h> #if CHAR_BIT != 8 #error