DIRECTIVEPublished
#define
#define <identificador> [<texto de substituição>]Defines identifiers, manifest constants, or pseudofunctions expanded by the preprocessor.
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.
Syntax
#define <identificador> [<texto de substituição>]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
ReturnExpected result
Identifiers are replaced before compilation and are not runtime variables.
Pseudofunction
#define AREA(nBase, nAltura) (nBase * nAltura)
User Function ExArea()
Local nResultado := AREA(10, 12)
ConOut(CValToChar(nResultado))
ReturnExpected result
The preprocessor expands AREA(10, 12) into its replacement expression.
- 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.
- 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.
