#define argument stringized but to a wide string L" instead of "

469 Views Asked by At

I need to stringify a #define argument to a wide string.

So while

#define c(x) x,#x

used as:

{c(maria),0,false},

gives:

{maria,"maria",0,false} // maria is a member of an enum.

I don't know how to do the same but creating a wide string.

What I mean is instead of having "maria" having L"maria"

2

There are 2 best solutions below

0
On

Why don't you try

#define c(x) x,L#x

EDIT: Apparently, this works only in Visual Studio. So you should go with L###x as others have suggested.

5
On

You can do:

#define c(x) x,L###x

The ## concatenation is necessary to combine the L and the quoted string into a single preprocessing token (as the L is part of a string-literal token).

#define c(x) x,L###x
c(Hello)

Sticking this through the preprocessor (with clang++ -E test.cpp) gives:

Hello,L"Hello"