Fabricio Fabricio - 4 years ago 99
C Question

How is "L" macro(?) defined?

static TCHAR szWindowClass[] = L"foo";


L
is "glued" to the string
"foo"
. How come? A function or a macro as I am used to is something like
L("foo");


Can anyone explain me how come L be glued to the string?

Answer Source

L is not a macro, it's just the standard prefix for wide (wchar_t, "Unicode") string literals; the concept is similar to the L suffix for long int literals, f suffix for float literals and so on1.

By the way, if you are using TCHARs you shouldn't be using L directly; instead, you should use the _T() or TEXT() macro, that adds L at the beginning of the literal if the application is compiled "for Unicode" (i.e. TCHAR is defined as WCHAR), or adds nothing if the compilation target is "ANSI" (TCHAR defined as CHAR).


  1. Although in my opinion this is confusing - why suffixes for arithmetic types and a prefix for wide string literals?
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download