Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

macro problem

31 views
Skip to first unread message

Darrian Peng Wang

unread,
Mar 8, 2002, 7:20:20 PM3/8/02
to
To have a wide character version of "__FILE__", MSDN document has a sample
#define WIDEN2(x) L ## x

#define WIDEN(x) WIDEN2(x)

#define __WFILE__ WIDEN2(__FILE__)

I do not understand why the above code works but the following one does not:

#define WIDEN(x) L ## x

#define __WFILE__ WIDEN(__FILE__)

Thax.

Darrian

Joseph M. Newcomer

unread,
Mar 10, 2002, 2:30:31 AM3/10/02
to
There is an order of evaluation here which is coming into play. If you write

#define WIDEN(x) L##x
#define __WFILE__ WIDEN(__FILE__)
it expands to
L__FILE__
which is not a valid name. But if you do

#define WIDEN2(x) L##x
#define WIDEN(x) WIDEN2(x)

then
WIDEN(__FILE__) first expands the argument __FILE__ and expands it as

WIDEN2("c:\here\there\file.cpp")
and then expands WIDEN2 as
L"c:\here\there\file.cpp")

years ago we referred to this as the "macro FUNARG problem" and we designed languages to
give us control of this explicitly. The C preprocessor was more-or-less thrown together
(and, as macro processors go, is a step backwards from what we knew how to do in 1973), so
kludges like this have to be done (and there are even deeper problems that there are no
kludges to get around)
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm

0 new messages