Preprocessor macro substitution

vbdis@aol.com (VBDis)
14 Mar 2003 11:29:50 -0500

          From comp.compilers

Related articles
Preprocessor macro substitution vbdis@aol.com (2003-03-14)
| List of all articles for this month |
From: vbdis@aol.com (VBDis)
Newsgroups: comp.compilers
Date: 14 Mar 2003 11:29:50 -0500
Organization: AOL Bertelsmann Online GmbH & Co. KG http://www.germany.aol.com
Keywords: macros, question
Posted-Date: 14 Mar 2003 11:29:50 EST

In writing an C++ preprocessor (with extended capabilities) I couldn't
find a complete specification for the evaluation of macros and their
arguments. Perhaps somebody can answer the following questions:


In former times the preprocessor acted on pure text, with the possible
substitution of a preprocessor symbol also in strings or
comments. Nowadays the preprocessor seems to tokenize the input first,
according to C/C++ syntax, so that strings and comments are never
modified?


How are #defines bound? It seems to me that all symbols are bound by name, so
that the latest definition of a preprocessor symbol is used?
#define A B
#define B Something
Here A evaluates to Something, or whatever is the last definition of B
before A is expanded.


One of my sources states that a macro name is not expanded when it occurs in
the definition of the macro itself:
#define A A
should always evaluate to A (no inifinite recursion), but what about
#define A B
#define B A
?


Such a construct will result in an indirect infinite recursion, which
should be detected somehow (how?).


Macro arguments seem to be expanded when they are used, not when they
are passed to the macro, otherwise the concatenation operator ##
couldn't work? Is the result of such a concatenation again subject to
macro substitution?


DoDi


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.