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-16. Predefined Macros
SymbolSet
ERRATA_4000_BOUNDARYWhen the ERRATA_4000 applies.
MPLAB_ICDWhen building for an MPLAB ICD debugger. Assigned 2 to 5 to indicate an MPLAB ICD 2 through MPLAB ICD 5, respectively.
_CHIPNAMEWhen 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.
_EEPROMSIZEWhen building for non-PIC18 devices. Indicates how many bytes of EEPROM are available.
_EEPROM_INTWhen 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_TYPESWhen the errata workaround is being applied, see -merrata option, 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_SIZEAlways. Indicates the size of the Flash program memory erase block. They do not represent Flash data memory.
_FLASH_WRITE_SIZEAlways. 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_INT24Always.
_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.
_PIC12When building for a Baseline device (12-bit instruction).
_PIC12EWhen building for an Enhanced Baseline device (12-bit instruction).
_PIC12IEWhen building for am Enhanced Baseline device with interrupts.
_PIC14When building for an Mid-range device (14-bit instruction).
_PIC14EWhen building for an Enhanced Mid-range device (14-bit instruction).
_PIC14EXWhen building for an extended-bank Enhanced Mid-range PIC device (14-bit instruction).
_PIC18When 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).
_RAMSIZEWhen building for a PIC18 device. Indicates how many bytes of data memory are available.
_ROMSIZEAlways. 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__Always
__CODECOVWhen code coverage is enabled, with value __CC_RAM (1).
__DATABANKWhen 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".
__DEBUGWhen performing a debug build and you are using the MPLAB X IDE.
__EXTMEMWhen device has external memory. Indicates the size of this memory.
__FILE__Always. Indicates the source file being preprocessed.
__FLASHTYPEWhen 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_PARTWhen 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_FLAGSAlways. Indicates the optimizations in effect (see text following this table).
__OPTIM_LEVELAlways. Indicates the optimization level selected, viz., 0 for -O0 and -Og, 1 for -O1, 2 for -O2, 3 for -O3, ad 4 for -Os.
__PICCPRO__ and 
__PICC__When building for any PIC10/12/14/16 device.
__PICC18__When not in C18 compatibility mode.
__RESETBITS_ADDRWhen 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__.
__STACKAlways. Assigned with __STACK_COMPILED (0x1), __STACK_HYBRID (0x2) or __STACK_REENTRANT (0x4) to indicate the global stack setting: compiled, hybrid or software, respectively.
__STDC_VERSION__Always. Assigned a long integer date code in the form yyyymm to indicate the C Standard version, e.g., 199901L or 199000L
__STRICTWhen 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.
__XCAlways. Indicates MPLAB XC compiler for Microchip is in use.
__XC8Always. Indicates MPLAB XC compiler for Microchip 8-bit devices is in use.
__XC8_VERSIONAlways, 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 following table can be used as bitwise AND masks to determine the value held by __OPTIM_FLAGS, hence the optimizations used.

Table 5-17. Optimization Flag Masks
MacroValueMeaning
__OPTIM_NONE0x0No optimizations applied (on equality).
__OPTIM_ASM0x1Assembler optimizations on C code.
__OPTIM_ASMFILE0x2Assembler optimizations on assembly source code.
__OPTIM_10x100Optimization level 1
__OPTIM_20x200Optimization level 2
__OPTIM_SPEED, __OPTIM_30x20000Optimized for speed.
__OPTIM_SPACE, __OPTIM_SIZE, __OPTIM_S0x40000Optimized for size.
__OPTIM_DEBUG, __OPTIM_G0x80000Optimized for accurate debug.
__OPTIM_LOCAL0x200000Local optimizations applied.