DIRECTIVEPublished
#ifdef
#ifdef <identificador> ... [#else ...] #endifIncludes a block in compilation only when a given identifier is defined.
Overview
#ifdef checks at preprocessing time for a symbol created by #define or supplied by the environment. Accepted code reaches the compiler; rejected code is absent from the final object.
Syntax
#ifdef <identificador> ... [#else ...] #endifCode controlled by a symbol
#define AMBIENTE_HOMOLOGACAO
User Function ExIfDef()
#ifdef AMBIENTE_HOMOLOGACAO
MsgInfo("Compilação de homologação")
#else
MsgInfo("Compilação padrão")
#endif
ReturnExpected result
Only one branch enters the compiled object.
- The decision happens at compilation, not runtime.
- Use #else for an alternative and always close with #endif.
- Do not use compilation symbols for operational configuration that must change without recompilation.
- Too many source variants increase testing cost.
