views:

74

answers:

2
#define NAME(x) TEXT(x)
#define TEXT(quote) __TEXT(quote)   // r_winnt
#define __TEXT(quote) quote         // r_winnt

The above is from winNT.h, isn't NAME("Virtual Cam") the same as "Virtual Cam",what's the point to use this macro?

+1  A: 

Depends on if your system is #defined to use Unicode. Then it will automatically change the literal for you to be a wide literal instead of a char literal.

DeadMG
But I don't see that logic above,how does it happen?
@user198729: see the `#ifdef UNICODE` `#else` part of the code in the header file.
Naveen
Where “use Unicode” means “use UTF-16 encoded Unicode,” since that is the Unicode encoding best supported by Microsoft tools and APIs.
Christopher Creutzig
+2  A: 

__TEXT macro expansion is selected based on whether UNICODE flag is defined or not. If not it just expands to quote else it will append L to the quote so that it becomes L"Virtual Cam" . This string is interpreted as a wide char string.

Naveen
Is `L` in `L"Virtual Cam"` a native syntax of C++ or defined in some header files?
I think it's native C++ code, since one can write wchar_t* pwstr = L"Test";
Stephane Rolland
the C++ ISO Standard referes to wchar_t as C native ;-). So L is not C++ native code, but C native code ;-)
Stephane Rolland
The '`L`' prefix to a string or character literal is in *both* the C and C++ language standards - it's how wide-character literals are formed in the source.
Michael Burr