Question

The following code doesn't compile in my VC++ 2010 project:

define MY_MAJOR_VERSION   20
define OLESTR_(str)       L##str
define MOLE( STR )        OLESTR_(#STR)
define MAKE_STR(STR)      MOLE(STR)

REGMAP_ENTRY(MAKE_STR(VERSION), MAKE_STR(MY_MAJOR_VERSION))

VERSION is NOT a macro definition, just text. In the end, I want:

REGMAP_ENTRY(L"VERSION", L"20")

but what I get, when I compile in Debug mode is:

REGMAP_ENTRY(L"VERSION", LL"20")

I'm thinking it's a project setting because I've used that in debug mode in other situations, but never with this problem. Is there a VC++ 2010 setting that would cause the stringizing operator to insert an L or _T?

Était-ce utile?

La solution

For me, this (note that I changed MAKE_STR to MAKE_OLESTR - I assume that was a typo in the code posted in the question):

#define MY_MAJOR_VERSION   20
#define OLESTR_(str)       L##str
#define MOLE( STR )        OLESTR_(#STR)
#define MAKE_OLESTR(STR)      MOLE(STR)

REGMAP_ENTRY(MAKE_OLESTR(VERSION), MAKE_OLESTR(MY_MAJOR_VERSION))

preprocesses to (as shown by cl /E test.c):

REGMAP_ENTRY(L"VERSION", L"20")

which seems to be what you want.

You may want to post something that can reproduced using a command line compile.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top