24.4.3 Far Objects and Functions
The __far
qualifier can be used to indicate that variables or functions
are located in ‘far memory’. Exactly what constitutes far memory is dependent on the
target device, but it is typically memory that requires more complex code to access.
Expressions involving far-qualified objects usually generate slower and larger 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
__far
specifier.
Example
The following shows a variable and function qualified using __far
.
__far int serialNo;
__far int ext_getCond(int selector);
Differences
When targeting PIC devices, the MPLAB XC8 compiler has allowed the far
specifier to be used with variables. This specifier has not been allowed with functions.
When targeting AVR devices, MPLAB XC8 has not implemented any “far” memory.
The MPLAB XC16 and XC-DSC compilers have used the far
attribute with
both variables and functions.
The MPLAB XC32 compiler has used the far
attribute with functions
only.
Migration to the CCI
When targeting PIC devices with the MPLAB XC8 compiler, change any occurrence of the
far
qualifier to __far
, for example, from:
far char template[20];
to:
__far char template[20];
When using MPLAB XC16, XC-DSC or XC32 compilers, change any occurrence of the
far
attribute to the __far
specifier, for example,
from:
void bar(void) __attribute__ ((far));
int tblIdx __attribute__ ((far));
to:
void __far bar(void);
int __far tblIdx;
Caveats
None.