What exactly is the L prefix in C++?

user965369 picture user965369 · Oct 26, 2012 · Viewed 33.9k times · Source

I understand what it does: specifies a string literal as a const wchar_t * (wide character string) instead of const char * (plain old characters), but how is it actually defined?

Is it a macro of some sort? Is it an operator for GCC compilers? What is it?

Answer

Kerrek SB picture Kerrek SB · Oct 26, 2012

The literal prefixes are a part of the core language, much like the suffixes:

'a'    // type: char
L'a'   // type: wchar_t

"a"    // type: char[2]
L"a"   // type: wchar_t[2]
U"a"   // type: char32_t[2]

1      // type: int
1U     // type: unsigned int

0.5    // type: double
0.5f   // type: float
0.5L   // type: long double

Note that wchar_t has nothing to do with Unicode. Here is an extended rant of mine on the topic.