#define/#undef
Define/Undefine
Constant
Directives
Syntax
#define
name[(arg, ... ,arg)] token-string
#undef
name
Description
The preprocessor supports
two
directives
for
defining and undefining con-
stants:
Example
B-2
• The
#define
directive assigns a string
to
a constant. Subsequent
occurrences of name
are
replaced by token-string. The name can
be
immediately followed by
an
argument list; the arguments
are
sepa-
rated by commas, and the list
is
enclosed
in
parentheses.
Each
oc-
currence
of
an
argument
is
replaced by the corresponding set
of
tokens from the comma-separated string.
When a macro
with
arguments
is
expanded, the arguments
are
placed
into the expanded token-string unchanged. After the entire token-
string
is
expanded, the preprocessor scans again for names
to
expand
at the beginning
of
the newly created token-string, which allows for
nested macros.
Note that there
is
no space between name and the open parenthesis
at
the beginning
of
the argument list. A trailing semicolon
is
not re-
quired;
if
used,
it
is
treated
as
part
of
the token-string.
• The
#undef
directive undefines the constant name; that
is,
it causes
the preprocessor
to
forget the definition
of
name.
The following example defines the constant
f:
#define
f(a,b,c)
3*a+b-c
The
following
line
of
code
uses
the definition
of
f:
f(27,begin,minus)
This line
is
expanded to:
3*27+begin-minus
To undefine
f,
enter:
#undef
f