5.14.2 Predefined Macros

The compiler drivers define certain symbols to the preprocessor, allowing conditional compilation based on chip type, etc. The symbols listed in the table below show the more common symbols defined by the drivers.

Each symbol, if defined, is equated to 1 (unless otherwise stated).

Table 5-15. Predefined Macros
Symbol Set
ERRATA_4000_BOUNDARY When the ERRATA_4000 applies.
HI_TECH_C When the C language variety is HI-TECH C compatible.
MPLAB_ICD When building for an MPLAB ICD debugger. Assigned 2 to 5 to indicate an MPLAB ICD 2 through MPLAB ICD 5, respectively.
_CHIPNAME When the specific chip type selected, e.g., _16F877.
_BANKBITS_ When building for non-PIC18 devices. Assigned 0, 1, or 2 to indicate 1, 2, or 4 available banks or RAM.
_BANKCOUNT_ When building for non-PIC18 devices. Indicates the number of banks of data memory implemented.
_COMMON_ When common RAM is present.
_COMMON_ADDR_ When common memory is present. Indicates common memory starting address.
_COMMON_SIZE_ When common memory is present. Indicates the common memory size.
_EEPROMSIZE When building for non-PIC18 devices. Indicates how many bytes of EEPROM are available.
_EEPROM_INT When building for non-PIC18 devices. Assigned a value of 2 (_NVMREG_INT), 1 (_EEREG_INT), or 0 (_NOREG_INT) to indicate the device uses the NVMREG, EEREG, or no register interface to access EEPROM.
_ERRATA_TYPES When the errata workaround is being applied, see -merrata option, 4.6.1.10 Errata Option.
_FAMILY_FAMILY_ When building for PIC18 devices and indicates the PIC18 family as indicated by the FAMILY field in the relevant .ini file in the compiler's pic/dat/ini directory.
_FLASH_ERASE_SIZE Always. Indicates the size of the Flash program memory erase block. They do not represent Flash data memory.
_FLASH_WRITE_SIZE Always. Indicates the size of the Flash program memory write block. They do not represent Flash data memory.
_GPRBITS_ When building for non-PIC18 devices. Assigned 0, 1, or 2 to indicate 1, 2, or 4 available banks or general purpose RAM.
_GPRCOUNT_ When building for non-PIC18 devices. Assigned a value which indicates the number of banks that contain general-purpose RAM.
_HAS_FUNCTIONLEVELPROF_ When -finstrument-functions is specified and target supports profiling.
_HAS_INT24 Always.
_HAS_OSCVAL_ When the target device has an oscillator calibration register.
_MPC_ When compiling for Microchip PIC MCU family.
_OMNI_CODE_ When compiling using an OCG compiler.
_PIC12 When building for a Baseline device (12-bit instruction).
_PIC12E When building for an Enhanced Baseline device (12-bit instruction).
_PIC12IE When building for am Enhanced Baseline device with interrupts.
_PIC14 When building for an Mid-range device (14-bit instruction).
_PIC14E When building for an Enhanced Mid-range device (14-bit instruction).
_PIC14EX When building for an extended-bank Enhanced Mid-range PIC device (14-bit instruction).
_PIC18 When building for a PIC18 device (16-bit instruction).
_PROGMEM_ When building for a Mid-range device with flash memory, and indicates the type of flash memory employed by the target device: 
values 0xFF (unknown)
0xF0 (none)
0 (read-only)
1 (word write with auto erase)
2 (block write with auto erase)
3 (block write with manual erase).
_RAMSIZE When building for a PIC18 device. Indicates how many bytes of data memory are available.
_ROMSIZE Always. Indicates how much program memory is available (byte units for PIC18 devices; words for other devices).
__CHIPNAME and
 __CHIPNAME__ When the specific chip type selected, e.g., __16F877.
__CLANG__ When the Clang frontend is in use (-std=c99).
__CODECOV When code coverage is enabled, with value __CC_RAM (1).
__DATABANK When eeprom or flash memory is implemented, and identifies in which bank the EEDATA/PMDATA register is found.
__DATE__ Always. Indicates the current date as a string literal, e.g., "May 21 2004".
__DEBUG When performing a debug build and you are using the MPLAB X IDE.
__EXTMEM When device has external memory. Indicates the size of this memory.
__FILE__ Always. Indicates the source file being preprocessed.
__FLASHTYPE When building for non-PIC18 devices with flash memory. Indicates the type of flash memory employed by the target device, see _PROGMEM below.
__LINE__ Always. Indicates this source line number.
__J_PART When building for a PIC18 ‘J’ series part.
__MPLAB_ICDX__ When compiling for an ICD debugger. X can be 2, 3, 4, or 5 indicating a Microchip MPLAB ICD 2, ICD 3, ICD 4, or ICD 5 respectively.
__MPLAB_ICE__ To indicate any In-circuit Emulator
__MPLAB_ICE4__ When compiling for a Microchip ICE 4 In-Circuit Emulator.
__MPLAB_PICKITX__ When compiling for a PICkit™. X can be 2, 3, 4, or 5 indicating a Microchip MPLAB PICkit 2, PICkit 3, PICkit 4, or PICkit 5, respectively.
__MPLAB_REALICE__ When compiling for a Microchip MPLAB REAL ICE™ In-Circuit Emulator.
__MPLAB_SNAP__ When compiling for a Microchip MPLAB Snap In-Circuit Debugger.
__OPTIMIZE_SPEED__ When using speed-orientated optimizations.
__OPTIMIZE_SPACE__ and
 __OPTIMIZE_SIZE__ When using space-orientated optimizations.
__OPTIMIZE_NONE__ When no optimizations are in effect.
__OPTIM_FLAGS Always. Indicates the optimizations in effect (see text following this table).
__PICCPRO__ and 
__PICC__ When building for any PIC10/12/14/16 device.
__PICC18__ When not in C18 compatibility mode.
__RESETBITS_ADDR When the STATUS register will be preserved. Indicates the address at which this register will be saved.
__SIZEOF_TYPE__ Always. Indicates the size in bytes of the specified type, e.g., __SIZEOF_INT__ or __SIZEOF___INT24__.
__STACK Always. Assigned with __STACK_COMPILED (0x1), __STACK_HYBRID (0x2) or __STACK_REENTRANT (0x4) to indicate the global stack setting: compiled, hybrid or software, respectively.
__STRICT When the -Wpedantic option is enabled.
__TIME__ Always. Indicates the current time as a string literal, e.g., “08:06:31”
__TRADITIONAL18__ When building for a PIC18 device. Indicates the non-extended instruction set is selected.
__XC Always. Indicates MPLAB XC compiler for Microchip is in use.
__XC8 Always. Indicates MPLAB XC compiler for Microchip 8-bit devices is in use.
__XC8_VERSION Always, and indicates the compiler’s version number multiplied by 1000, e.g., v1.00 will be represented by 1000.

The compiler-defined macros shown in the Table 5-16 table can be used as bitwise AND masks to determine the value held by __OPTIM_FLAGS, hence the optimizations used.

Table 5-16. Optimization Flags
Macro Value Meaning
__OPTIM_NONE 0x0 No optimizations applied (on equality).
__OPTIM_ASM 0x1 Assembler optimizations on C code.
__OPTIM_ASMFILE 0x2 Assembler optimizations on assembly source code.
__OPTIM_SPEED 0x20000 Optimized for speed.
__OPTIM_SPACE 0x40000 Optimized for size.
__OPTIM_SIZE 0x40000 Optimized for size.
__OPTIM_DEBUG 0x80000 Optimized for accurate debug.
__OPTIM_LOCAL 0x200000 Local optimizations applied.