Standard Clarification
Wm E Davidsen Jr
davidsen at crdos1.crd.ge.COM
Wed Oct 25 03:35:17 AEST 1989
In article <1989Oct21.233915.23217 at utzoo.uucp>, henry at utzoo.uucp (Henry Spencer) writes:
| Section 3.8.3 (Oct 1988 draft, roughly current except for wording changes):
|
| "If a # preprocessing token, followed by an identifier, occurs lexically
| at the point at which a preprocessing directive could begin, the identifier
| is not subject to macro replacement."
|
| In other words, ANSI C specifically says that it *doesn't* work.
Another thing doesn't work, although it would be useful. If you have
macros of the form:
#define FOO 123
#define BAR FOO
#define DEMO(c) printf("Demo:"#c"\n")
then:
DEMO(BAR);
does not do a substitution of FOO for BAR, nor 123 for FOO. To make this
work the value of the argument must be forced to be evaluated first.
#define XDEMO(c) DEMO(c)
and:
XDEMO(BAR);
now substitutes 123. This is how I would expect it to work, from the
section you quote. Both gcc and a beta of MSC work just that way.
Test prog for the terminally curious:
#define FOO 123
#define BAR FOO
#define X(c) printf("X:"#c"\n")
#define TMP(c) X(c)
X(FOO);
X(BAR);
TMP(BAR);
--
bill davidsen (davidsen at crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon
More information about the Comp.lang.c
mailing list