RAD Studio
ContentsIndex
PreviousUpNext
#define

Syntax

#define macro_identifier <token_sequence>

Description 

The #define directive defines a macro. Macros provide a mechanism for token replacement with or without a set of formal, function-like parameters. 

Each occurrence of macro_identifier in your source code following this control line will be replaced in the original position with the possibly empty token_sequence (there are some exceptions, which are noted later). Such replacements are known as macro expansions. The token sequence is sometimes called the body of the macro. 

An empty token sequence results in the removal of each affected macro identifier from the source code. 

After each individual macro expansion, a further scan is made of the newly expanded text. This allows for the possibility of nested macros: The expanded text can contain macro identifiers that are subject to replacement. However, if the macro expands into what looks like a preprocessing directive, the directive will not be recognized by the preprocessor. There are these restrictions to macro expansion:

  • Any occurrences of the macro identifier found within literal strings, character constants, or comments in the source code are not expanded.
  • A macro won't be expanded during its own expansion (so #define A A won't expand indefinitely).
Example

#define HI "Have a nice day!"
#define empty
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!