Skip to content

The Preprocessor

The preprocessor filters code by evaluating directive statements and macro defines. The macro defines can only be defined by the compiler program options: -D. e.g. -DMACRO=1, which defines MACRO as 1. Macro identifiers cannot start with numerical figures. Their first letter must be an ASCII character within "a-z" or "A-Z."

The Directives:

#if, #elif, #else, #ifdef, #ifndef, #elifdef, #elifndef, #warning, #error, defined(), and #endif.

Example Code

#if, #elif, #else, and #endif.

#if VERSION == 1

#elif VERSION == 2

#else VERSION == 3

#endif

#ifdef, #ifndef, #elifdef, and #elifndef.

#ifdef VERSION

#elifdef VERSION

#endif


#ifndef VERSION2

#elifndef VERSION2

#endif

#warning, #error, and defined().

#if defined(APPLE)
    #warning This is a warning
#endif

#if !defined(CLANG)
    #error this is an error
#endif