Article View: comp.std.c
Article #3283Re: Macro replacement
From: Andrew Waters
Date: Fri, 22 Jan 1993 12:14
Date: Fri, 22 Jan 1993 12:14
32 lines
1865 bytes
1865 bytes
The example given in the standard (section 3.8.3.5) makes use of an ambiguity
pointed out in the rational.
e.g. (taking only the relavent part)
#define x 2
#define f(a) f(x * (a))
#define g f
#define t(a) a
t(t(g)(0))
which the standard has going to f(2 * (0)) however if we follow the expansion:
1. Examine the string and find the outermost macro name "t"
2. Search for the argument "t(g)(0)"
3. Expand the arguments - finding the inner macro name "t"
4. Search for the argument "g"
5. Expand the arguments - finding the macro name "g" which expands to "f"
6. Rescan the replacement list of "g" i.e. rescan "f". There is a macro f
but it requires an open parenthesis which we do not have therefore we cannot
expand any further.
7. Rescan the replacement list of innermost "t" i.e. rescan "f". This has
already been expanded fully.
8. Rescan the replacement list of outermost "t" i.e. rescan "f(0)". Now what
happens. Clearly there is a macro call however "f" is a macro name which
has not been replaced and therefore is not available for further replacement.
So we have two answers
"f(2 * (0))" in the standard, but just as legally "f(0)". Surely a poor
example to illustrate expansion rules.
Technical Details
Message-ID:
<1993Jan22.121437.10384@csqx.cs.rhbnc.ac.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!doc.ic.ac.uk!rhbnc!cscx!andrewwReferences:
<SJA.93Jan16184647@lk-hp-2.hut.fi> <1ja816INNhlh@chnews.intel.com> <526@heimdall.sdrc.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!doc.ic.ac.uk!rhbnc!cscx!andreww From: andreww@cscx.cs.rhbnc.ac.uk (Andrew Waters) Subject: Re: Macro replacement Message-ID: <1993Jan22.121437.10384@csqx.cs.rhbnc.ac.uk> Sender: andreww@cscx (Andrew Waters) Nntp-Posting-Host: cscx.rhbnc.ac.uk Reply-To: andreww@dcs.rhbnc.ac.uk (Andrew Waters) Organization: Dept of Comp Sci, Royal Holloway & Bedford New College Uni London References: <SJA.93Jan16184647@lk-hp-2.hut.fi> <1ja816INNhlh@chnews.intel.com> <526@heimdall.sdrc.com> Date: Fri, 22 Jan 1993 12:14:37 GMT Lines: 32