🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5702

macro expansion

#5702
From: Walter Bright
Date: Mon, 06 Feb 1989 23:49
31 lines
1187 bytes
I'm having a bit of trouble understanding macro expansion under ANSI C.
Given the source:

	#define A A) + A
	#define str(s) #s
	#define xstr(s) str(s)

Does xstr(A) expand to:
1)	"A" + A)
or:
2)	"A) + A"

If you say 1), then this is very hard to implement due to the rule that
however macros nest, circular macro references won't be expanded. The reason
is that 1) comes about because:
	xstr(A)
	str(A) + A)
Note at this stage that the expansion for A occurs both as a parameter and
as a 'tail' occuring afterwards. Very clumsy and confusing.

BTW, things would be much simpler if ANSI stated that the arguments to
a macro are not macro expanded until *AFTER* the macro they are an
argument to is expanded. I.e.
	#define A 1
	#define str(s) #s
	#define xstr(s) str(s)

xstr(A) expands to:
	"1"
instead of the more reasonable:
	"A"
Technical Details
Message-ID: <1863@dataio.Data-IO.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!uw-entropy!dataio!bright

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!uw-entropy!dataio!bright
From: bright@Data-IO.COM (Walter Bright)
Newsgroups: comp.std.c
Subject: macro expansion
Message-ID: <1863@dataio.Data-IO.COM>
Date: 6 Feb 89 23:49:34 GMT
Organization: Data I/O Corporation; Redmond, WA
Lines: 31