Usina BRAdvPL Guide
Sign in
← All topics
DIRECTIVEPublished

#define

#define <identificador> [<texto de substituição>]

Defines identifiers, manifest constants, or pseudofunctions expanded by the preprocessor.

Pré-processadorConstantesPseudofunçõesCompilação
01 · OVERVIEW

Overview

#define associates a case-sensitive identifier with replacement text. Expansion happens during preprocessing, before compilation, and does not create a runtime variable. It may also define a valueless control symbol for #ifdef and #ifndef.

02 · SYNTAX

Syntax

#define <identificador> [<texto de substituição>]
03 · PRACTICAL EXAMPLE

Manifest constants

#define MAX_PRODUCTS 150
#define ERROR_MESSAGE "Invalid operation for this user."

User Function ExDefine()
    Local nQuantity := 151

    If nQuantity > MAX_PRODUCTS
        MsgStop(ERROR_MESSAGE, "Validation")
    EndIf
Return
Expected result

Identifiers are replaced before compilation and are not runtime variables.

04 · PRACTICAL EXAMPLE

Pseudofunction

#define AREA(nBase, nAltura) (nBase * nAltura)

User Function ExArea()
    Local nResultado := AREA(10, 12)

    ConOut(CValToChar(nResultado))
Return
Expected result

The preprocessor expands AREA(10, 12) into its replacement expression.

BEST PRACTICES
  • Use uppercase names by convention.
  • #define can create a manifest constant, control symbol, or argument-based pseudofunction.
  • Wrap pseudofunction expressions in parentheses to preserve precedence.
  • The definition is visible from its declaration point in the processed source unit.
COMMON PITFALLS
  • Replacement is textual; unsafe pseudofunctions may evaluate side effects more than once.
  • Do not hide complex logic in #define; prefer a real function when debugging or types matter.
  • Defined identifiers are case-sensitive.

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