D
Dave Ohlsson
Hi,
In ISO C/C++, a string constant prefixed by the letter `L' is a wide
string constant and is of type "array of wchar_t".
Consider the following C program fragment:
#include <stdio.h>
int main()
{
const wchar_t* my_string = L"a";
wprintf(my_string);
return 0;
}
This compiles fine (and even seems to work). Now, suppose that "a" is
defined through a macro (presumable in another source file):
#define STRING_LITERAL "a"
QUESTION: How does one define a wide-character string based on
`STRING_LITERAL'?
Naturally, this fails miserably:
const wchar_t* my_string = LSTRING_LITERAL;
because the compiler treats `LSTRING_LITERAL' as a single token.
This does not work either:
const wchar_t* my_string = L STRING_LITERAL;
because there may be no space between `L' and the string within double
quotes.
Any idea?
-- dave
In ISO C/C++, a string constant prefixed by the letter `L' is a wide
string constant and is of type "array of wchar_t".
Consider the following C program fragment:
#include <stdio.h>
int main()
{
const wchar_t* my_string = L"a";
wprintf(my_string);
return 0;
}
This compiles fine (and even seems to work). Now, suppose that "a" is
defined through a macro (presumable in another source file):
#define STRING_LITERAL "a"
QUESTION: How does one define a wide-character string based on
`STRING_LITERAL'?
Naturally, this fails miserably:
const wchar_t* my_string = LSTRING_LITERAL;
because the compiler treats `LSTRING_LITERAL' as a single token.
This does not work either:
const wchar_t* my_string = L STRING_LITERAL;
because there may be no space between `L' and the string within double
quotes.
Any idea?
-- dave