How SHOULD these macros work?
Zev Sero
zvs at bby.oz.au
Tue Feb 19 13:40:59 AEST 1991
Eric = schweitz at lexvmc.iinus1.ibm.com ("Eric Schweitz")
Eric> I have a question concerning the preprocessor. Namely, what behavior
Eric> SHOULD be expected from the following:
Eric> #define one val1,val2
Eric> #define two(arg1,arg2) arg1+arg2
Eric> ....
Eric> two (one) // ?
Eric> Should this evaluate to:
Eric> a) val1+val2
Eric> -or-
Eric> b) val1,val2+
The correct answer is b. I quote from H&S 2, page 33:
Once a macro call has been expanded, the scan for macro calls
resumes at the beginning of the expansion; this is so that names of
macros may be recognized within the expansion for the purpose of
further macro replacement...Macro replacement is also not performed
within the actual argument token strings of a complex macro call at
the time the macro call is being scanned. Macro names are recognised
within actual argument token strings only during the rescanning of
the expansion.
Therefore your macro is expanded in the following steps:
two (one) --> one+
At this point one is not recognised as a macro. Then the expression is
rescanned:
one+ --> val1,val2+
--
Zev Sero - zvs at bby.oz.au
This I say unto you, be not sexist pigs.
- The prophetess, Morgori Oestrydingh (S.Tepper)
More information about the Comp.lang.c
mailing list