Usina BRAdvPL Guide
Sign in
← All topics
DIRECTIVEPublished

#else and #endif

#ifdef <id> ... #else ... #endif

Provides the alternative path and closes conditional compilation blocks.

Compilação condicionalPré-processadorBlocos
01 · OVERVIEW

Overview

#else separates the alternative for #ifdef or #ifndef, and #endif closes the block. Unlike runtime If/Else/EndIf, these directives select source text before compilation.

02 · SYNTAX

Syntax

#ifdef <id> ... #else ... #endif
03 · PRACTICAL EXAMPLE

Two compilation variants

User Function ExAlternativa()
#ifdef VERSAO_ESPECIAL
    MsgInfo("Recurso da versão especial")
#else
    MsgInfo("Comportamento padrão")
#endif
Return
Expected result

Only the matching alternative reaches the compiler.

BEST PRACTICES
  • Indent content to expose the conditional structure.
  • Keep opening and closing directives close when practical.
COMMON PITFALLS
  • They do not replace runtime Else and EndIf.
  • Deeply nested blocks obscure which variant was compiled.

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