Usina BRAdvPL Guide
Sign in
← All topics
DIRECTIVEPublished

#ifdef

#ifdef <identificador> ... [#else ...] #endif

Includes a block in compilation only when a given identifier is defined.

Compilação condicionalPré-processadorAmbientes
01 · OVERVIEW

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.

02 · SYNTAX

Syntax

#ifdef <identificador> ... [#else ...] #endif
03 · PRACTICAL EXAMPLE

Code 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
Return
Expected result

Only one branch enters the compiled object.

BEST PRACTICES
  • The decision happens at compilation, not runtime.
  • Use #else for an alternative and always close with #endif.
COMMON PITFALLS
  • Do not use compilation symbols for operational configuration that must change without recompilation.
  • Too many source variants increase testing cost.

Related content

REFERENCES
  1. TOTVS. #define. TDN. Última alteração em 22 mar. 2019.
  2. TOTVS. Diretivas para o compilador. TDN.
  3. TOTVS. #ifdef. TDN.
  4. TOTVS. #ifndef. TDN.
  5. TOTVS. #include. TDN.
  6. TOTVS. #undef. TDN.
Status
Published
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR