home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!psinntp!heimdall!thor!scjones
- From: scjones@thor.sdrc.com (Larry Jones)
- Newsgroups: comp.std.c
- Subject: Re: Macro replacement
- Message-ID: <526@heimdall.sdrc.com>
- Date: 21 Jan 93 15:42:47 GMT
- References: <SJA.93Jan16184647@lk-hp-2.hut.fi> <1ja816INNhlh@chnews.intel.com>
- Sender: news@heimdall.sdrc.com
- Lines: 37
-
- In article <1993Jan19.180718.3482@csqx.cs.rhbnc.ac.uk> [which hasn't
- arrived here yet], andreww@cscx.cs.rhbnc.ac.uk (Andrew Waters) writes:
- > Is this truely more logical? Look at the example:
- >
- > #define echo(a) { a ; x }
- > #define x 2 * x
- > echo (x)
- >
- > As before the macro argument "x" is replaced giving the replacement list
- >
- > { 2 * x ; x }
- >
- > We now examine this replacement list for further macro expansion. "x" is no
- > longer available for replacement, giving the final result
- >
- > { 2 * x ; x }
-
- No. The rule in the standard about nonreplacable macro names says:
-
- These nonreplaced macro name preprocessing tokens are no longer
- available for further replacement...
-
- Note carefully that it's talking about the individual preprocessing
- tokens, not the macro in general. Thus, when "x" is expanded to "2 * x"
- in the above example, the "x" in the replacement string is not replaced
- and *that particular token* is marked unavailable for further
- replacement, not the macro x. Thus, when "{ 2 * x ; x }" is rescanned,
- the first "x" would be replacable, but it has been marked and so is left
- alone. The second "x" has not been marked, so it is replaced normally
- giving "{ 2 * x ; 2 * x }". Now the second "x" has also been marked so
- that if this string is later rescanned neither "x" will be replaced
- again.
- ----
- Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH 45150-2789 513-576-2070
- larry.jones@sdrc.com
- It doesn't have a moral, does it? I hate being told how to live my life.
- -- Calvin
-