24.4.4 Near Objects

The __near qualifier can be used to indicate that variables or functions are located in ‘near memory’. Exactly what constitutes near memory is dependent on the target device, but it is typically memory that can be accessed with less complex code. Expressions involving near-qualified objects generally are faster and result in smaller code.

Use the native keywords discussed in the Differences section to look up information on the semantics of this qualifier.

Some devices may not have such memory implemented, in which case, use of this qualifier is ignored. Stack-based (auto and parameter) variables cannot use the __near specifier.

Example

The following shows a variable and function qualified using __near.

__near int serialNo;

__near int ext_getCond(int selector);

Differences

When targeting PIC devices, the MPLAB XC8 compiler has allowed the near specifier to be used with variables. This specifier has not been allowed with functions. When targeting AVR devices, MPLAB XC8 has not implemented any “near” memory.

The MPLAB XC16 and XC-DSC compilers have used the near attribute with both variables and functions.

The MPLAB XC32 compiler has used the near attribute for functions, only.

Migration to the CCI

When targeting PIC devices with the MPLAB XC8 compiler, change any occurrence of the near qualifier to __near, for example, from:

near char template[20];

to:

__near char template[20];

When using the other compilers, change any occurrence of the near attribute to the __near specifier, for example, from:

void bar(void) __attribute__ ((near));

int tblIdx __attribute__ ((near));

to

void __near bar(void);

int __near tblIdx;

Caveats

None.