You can use #ifdef
to check if a constant was previously defined with a #define
directive or CONST
statment. If the constant has been previously defined, the statements inside the #if…#endif
block will be compiled, otherwise they will be discarded.
#define LOWMODEL 0 #ifdef LOWMODEL Low 0 #endif
In the above example, since LOWMODEL
is defined, the statement LOW 0
is compiled.
#else #elseifdef
may be used for more complex expressions as shown below:
#ifdef LOWMODEL Low 0 #elseifdef HIGHMODEL High 0 #else Low 1 #endif
#ifndef
is the opposite of the #ifdef
directive. If a constant has not been defined, the statements inside a #ifndef…#endif
block will be compiled, otherwise the statements will be discarded.
#define LOWMODEL 0 #ifndef LOWMODEL Low 0 #endif
#elseifndef
and #else
may be used for more complex expressions as shown below:
#ifndef LOWMODEL Low 0 #elseifndef HIGHMODEL High 0 #else Low 1 #endif
Finally, the directives may be mixed as shown below:
#if MODELNO = 0 Low 0 #elseifdef HIGHMODEL High 0 #else Low 1 #endif
Nested #ifdef
/#ifndef
directives are not supported; #ifdef
/#ifndef
may not be used inside another #ifdef
/#ifndef
.
See also #if...#endif.