96
Section 2: Compiler
TI
-
89 / TI
-
92 Plus Sierra C Assembler Reference Manual
Not for Distribution
Beta Version February 2, 2001
2.16.3. Macro
Replacement
The
#define directive is used to define a macro. It has two forms, depending on
whether the identifier to be defined is immediately followed by a left parenthesis.
A preprocessing directive of the following form defines an object-like macro:
#define macro_name replacement_list
It causes each subsequent instance of the macro name to be replaced by the
replacement list that constitutes the remainder of the directive. The replacement
list is then rescanned for more macro names as specified below.
A preprocessing directive of the following form defines a function-like macro with
arguments that is similar in appearance to a function call:
#define macro_name(identifier_list) replacement_list
The parameters are specified by the optional identifier list. Each subsequent
instance of the function-like macro name followed by a left parenthesis
introduces the sequence of preprocessing tokens that is replaced by the
replacement list in the definition. (A function-like macro name that is not followed
by a left parenthesis is not recognized as a macro name and no replacement is
made.) The replaced sequence is terminated by the matching right parenthesis,
skipping intervening matched pairs of left and right parenthesis. Within the
sequence that comprises an invocation of a function-like macro, a newline is
considered a normal whitespace character.
The sequence of tokens bounded by the outermost matching parentheses forms
the argument list for the function-like macro. The individual arguments within the
list are separated by commas; commas in the list enclosed within nested
parenthesis do not separate arguments. The number of comma-separated
arguments in the list must match the number of parameters in the function-like
macro definition.
2.16.3.1. Argument
Substitution
After the arguments in a function-like macro are identified, argument substitution
takes place. Each parameter in the replacement list, unless preceded by a ' # ' or
' ## ' preprocessor operator or followed by a ' ## ' operator, is replaced by the
macro expansion of the corresponding argument from the argument list. In other
words, each argument, unless its parameter is associated with a ' # ' or ' ## '
operator, is fully expanded (i.e., all macros replaced) before it is substituted into
the replacement list.