What is 'unsigned char near'?

The MCU specified here is a Freescale MC9C08 series, which uses a slightly enhanced version of their HC08 architecture. This is an 8-bit core, which (like many such) has shorter instructions and faster access to "zero page" addresses than others. Zero-page addresses are only 8 bits long instead of 16 bits, so instructions referencing them can be 2 bytes instead of 3, and take 1 cycle less to execute as a result.

The "near" keyword instructs the compiler to put the variable in "zero page" if possible, for better performance. Compilers specifically written for embedded development, such as this one, usually implement such extensions to the language (here described as "C Support for Zero Page").


Depending on the CPU architecture there may be different instructions to access data at different address. Here is an example from Keil for one of their compilers.

The near access has a certain memory limit, so you may give hints to the compiler to place some frequently used variables in an area that is accessible by shorter instructions (obviously describing access to an 32-bit address space is larger than 16-bit address space). This can translate to smaller/faster code.