16. Preprocessor¶
This chapter briefly describes the preprocessor and covers commonly used macros.
16.1. Overview¶
The preprocessor adheres to Standard C, providing:
Predefined macros for inspecting the compilation environment, allowing application tuning based on compiler properties.
User-defined macros, specified via the command line or within C source files.
The ability to dump the preprocessor environment for inspection.
The ability to dump the source file after preprocessing.
Predefined macros¶
The following describes the macros which are the ones you are most likely to use in conditional builds.
__STDC__¶
This macro is set to 1, indicating that this compiler adheres to Standard C.
__STDC_HOSTED__¶
This macro is defined as 0, indicating a cross-compiler. You can test this as follows:
#if defined(__STDC_HOSTED__) && __STDC_HOSTED__ == 0
__STDC_VERSION__¶
This macro is set to 199901L to indicate that this compiler
adheres to the ISO/IEC 9899:1999 standard.
__CALYPSI__¶
This macro is set to 1, indicating that either the assembler or compiler in use is from Calypsi.
__CALYPSI_CC__¶
This is set to 1, indicating that this is a Calypsi C compiler.
__CALYPSI_ASSEMBLER__¶
This macro is set to 1 when a Calypsi assembler is used.
__CALYPSI_DEBUG__¶
This macro is defined and set to 1 when compiling with debug
information enabled, i.e. --debug or -g command-line option
used.
__CALYPSI_VERSION_MAJOR__¶
This macro is set to the first number of the version.
__CALYPSI_VERSION_MINOR__¶
This macro is set to the second number of the version.
__BIG_ENDIAN__¶
This macro is defined if the target has big-endian byte order.
__LITTLE_ENDIAN__¶
This macro is defined if the target has little-endian byte order.
__BYTE_ORDER__¶
This macro defines the byte order, taking the value of __ORDER_LITTLE_ENDIAN__,
__ORDER_BIG_ENDIAN__, or __ORDER_PDP_ENDIAN__.
It is usually simpler to use __BIG_ENDIAN__ or __LITTLE_ENDIAN__
macros for conditional inclusion of endian-dependent source code.
__ORDER_LITTLE_ENDIAN__¶
This macro is defined to 1234 to describe the byte order in memory for a little-endian target.
__ORDER_BIG_ENDIAN__¶
This macro is defined as 4321, describing the byte order in memory for a big-endian target.
__ORDER_PDP_ENDIAN__¶
This macro is defined as 3412, describing the byte order in memory for a PDP-endian target.
__FILE__¶
This macro expands to the name of the current source file.
__LINE__¶
This macro expands to the current line number in the source file.
__DATE__¶
This macro expands to the current date.
__TIME__¶
This macro expands to the current time of the day.
__COUNTER__¶
This macro expands to a number that increments every time the macro is used.
__CALYPSI_TARGET_6502__¶
Set to 1 when the target is the 6502 family.
__CALYPSI_CORE_6502__¶
Set to 1 when the 6502 core is selected. Undefined for other cores.
You can test for this core using #ifdef __CALYPSI_CORE_6502__.
__CALYPSI_CORE_65B02__¶
Set to 1 when the 65B02 core is selected. Undefined for other cores.
You can test if the core is 6502 using #ifdef
__CALYPSI_CORE_65B02__.
__CALYPSI_CORE_65C02__¶
Set to 1 when the 65C02 core with Rockwell extensions is selected.
Undefined for other cores.
You can test if the core is 65C02 using #ifdef
__CALYPSI_CORE_65C02__.
__CALYPSI_CORE_65CNR02__¶
Set to 1 when the 65CNR02 core without Rockwell extensions is selected.
Undefined for other cores.
You can test if the core is 65CNR02 using #ifdef
__CALYPSI_CORE_65CNR02__.
__CALYPSI_CORE_45GS02__¶
Set to 1 when the 45GS02 core (used in the MEGA65 8-bit computer)
is selected. Undefined for other cores.
You can test if the core is 45GS02 using #ifdef
__CALYPSI_CORE_45GS02__.
__CALYPSI_TARGET_SYSTEM_EMBEDDED__¶
Set to 1 when the compiler is configured for an embedded system,
generating code suitable for flash or ROM memory.
You can test if the compiler is configured for an embedded system using #ifdef
__CALYPSI_TARGET_SYSTEM_EMBEDDED__.
__CALYPSI_TARGET_SYSTEM_C64__¶
Set to 1 when the compiler is configured for the Commodore 64 target.
__CALYPSI_TARGET_SYSTEM_MEGA65__¶
Set to 1 when the compiler is configured for the MEGA65 target.
__CALYPSI_CODE_MODEL_PLAIN__¶
Set to 1 if the compiler uses the Plain code model.
__CALYPSI_CODE_SLOT__¶
This macro is defined for the MEGA65 target and holds the value of the selected data slot, possible values are 0–7.