5.3.6.3.2 Pointer Classifications with Local Optimization

Where local optimizations have been enabled, pointers can have a size and classification based purely on their definition, not on the targets assigned to them by the program.

The pointer-target specifiers, __ram and __rom, (see 5.3.6.2 Pointer-target Qualifiers) can be used to ensure that addresses assigned to a pointer during the program’s execution are within an intended memory space. Together with a restricted range of pointer classifications, this ensures that pointers will have a size that is predictable.

Pointers defined in code built with local optimizations and which have the indicated targets will have the following sizes, where type is a valid, unqualified C type.

const type *
can be assigned the address of any object in data or program memory. These pointers will be 3 bytes wide if the program is being built for a PIC18 device that has more than 64 KB of program memory; they will be 2 bytes wide, otherwise.
__rom type *
can be assigned the address of any object in program memory, and attempts to assign the address of a data memory object will result in an error. These pointers will be 3 bytes wide if the program is being built for a PIC18 device that has more than 64 KB of program memory; they will be 2 bytes wide, otherwise. The const specifier can be optionally used with __rom without changing the pointer size.
type *
can be assigned the address of any object in data memory. As per normal operation, the compiler will issue a warning if the address of a const object is assigned to such pointers. These pointers are always 2 bytes in size.
__ram type *
can be assigned the address of any object in data memory and attempts to assign the address of a program memory object will result in an error. These pointers will always be 2 bytes in size. The presence of the const specifier indicates only that the target objects must be treated as read-only. The const specifier can be optionally used with __ram without changing the pointer size.

The size and operation of pointers to __far, pointers to __eeprom, and function pointers are not affected by the local optimization setting.