Programs that determine the host's byte order, host's byte order
Int main (int argc, char ** argv) {union {short s; char c [sizeof (short)];} un; un. s = 0x0102; if (sizeof (short) = 2) {if (un. c [0] = 1 & un. c [1] = 2) printf ("big end \ n"); else if (un. c [0] = 2 & un. c [1] = 1) printf (" \ n"); else printf ("unknown \ n") ;}exit (0 );}
Consider a 16-bit short integer, which consists of two bytes. There are two methods to store these two bytes in memory: one is to store the low-order bytes at the starting address, which is called the small-end byte order; another method is to store high-order bytes at the starting address, which is called large-end bytecode.
The method to determine the host's byte order is to use a consortium to define a short and a short byte size array. In this way, the short, address storage solution that can obtain this value through array representation.