Data Allocation Defines

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

The Compiler provides the "endian" macros listed in the following table.

Table 1. Compiler macros for defining "endianness"
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 differences between little endian and big endian (refer to the following listing).

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

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