[comp.lang.c] Preprocessing mystery

adrian@mti.mti.com (Adrian McCarthy) (02/24/90)

I'm trying to understand some of the darker secrets of ANSI preprocessing. 
Unfortunately the only ANSI reference I have currently is K&R 2 (mostly
Appendix A).

Consider "#define FOO(x,y,z) x##y##z"

(The ## things in the substitution text are an ANSI-added feature that is
useful for concatentating parameters.  In other words "FOO(a,b,c)" will become
"abc".)

My question is what would happen with "FOO(F,O,O)(a,b,c)"?  The first pass will
replace "FOO(F,O,O)" with "FOO", leaving us with "FOO(a,b,c)".

Appendix A now says:  "... the replacement token sequence is repeatedly
rescanned for more defined identifiers.  However, once a given identifier has
been replaced in a given expansion, it is not replaced if it turns up again
during rescanning; instead it is left unchanged."

So I'd assume that this new incarnation of "FOO" is left alone, yielding
"FOO(a,b,c)" rather than "abc". Is this correct?

I guess my confusion stems from the term "given expansion".  Just what is the
scope of a "given expansion"?  When, in the process of expanding a macro, an 
argument to the macro is expanded, is that a different "given expansion"?

Aid.

P.S.  Email and I'll summarize.