|C Preprocessor - macro expansion Mark_Kuschnir@gec-epl.co.uk (1993-05-24)|
|Re: C Preprocessor - macro expansion firstname.lastname@example.org (1993-05-24)|
|From:||email@example.com (David Moore)|
|Date:||Mon, 24 May 1993 21:59:09 GMT|
[In ANSI C]
> #define x 2
> #define f(a) f(x * (a))
> #define z z 
>this should macro expand to :
> f(2 * (f(2 * (z ))))
>I would like to know the steps I have to go through when macro expanding
>the above example so as to meet the ANSI provisos :
>(i) the replacement sequence is rescanned until all macros have been
>(ii) once an identifier has been used in a replacement sequence
> it won't be used again
The key seems to be in the definition of "expansion sequence". It looks
to me as if the term is meant to mean a tree.
For example, you start with f(f(z)) and after the first substitution
(using the fact that inside-out is mandated, you get:
That is, the % is a place holder for the text that is in the
which you now expand recursively, but with the f definition marked as
unusable. So you get at step 2 (and lumping together both
expansions to save space):
2 z 
Whenever you expand, you inherit the list of used definitions from
the parent and add the expansion you have just used - actually, of
course, you just keep parent links and walk up the tree to determine
what expansions you have already used.
I had no idea C macro expansion was this complicated!
Return to the
Search the comp.compilers archives again.