Usina BRAdvPL Guide
Sign in
← All topics
DIRECTIVEPublished

#ifndef

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

Includes a block only when a given identifier is not defined.

Compilação condicionalValores padrãoPré-processador
01 · OVERVIEW

Overview

#ifndef is the inverse of #ifdef. It is useful for header guards and defaults: the block remains only when the symbol does not exist at that preprocessing point.

02 · SYNTAX

Syntax

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

Protected default value

#ifndef BANCO_DADOS_PADRAO
    #define BANCO_DADOS_PADRAO "MSSQL"
#endif

User Function ExIfNDef()
    ConOut("Banco padrão: " + BANCO_DADOS_PADRAO)
Return
Expected result

MSSQL is defined only when no previous definition is active.

BEST PRACTICES
  • Use it to provide a default without overriding an earlier definition.
  • Always close with #endif.
COMMON PITFALLS
  • Changing a compiled default requires recompilation.
  • An undefined symbol is not the same as a false logical value.

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