Data Allocation Defines

The Compiler provides two macros that define data organization in memory: Little Endian (least significant byte first in memory) or Big Endian (most significant byte first in memory).

The Compiler provides the data a llocation macros listed in the following table.

Table 1. Compiler Macros Defining Little or Big Endian
Name Defined
__LITTLE_ENDIAN__ Defined if the Compiler allocates in Little Endian order
__BIG_ENDIAN__ Defined if the Compiler allocates in Big Endian order

The following example illustrates the difference between little and big endian.

Listing: Little vs. Big Endian
unsigned long L  = 0x87654321;
unsigned short s = *(unsigned short*)&L; // BE: 0x8765,LE: 0x4321

unsigned char c  = *(unsigned char*)&L; // BE: 0x87,  LE: 0x21