How is "L" macro(?) defined?

c, winapi

Solution

`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 `TCHAR`s 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`).

- Although in my opinion this is confusing - why suffixes for arithmetic types and a prefix for wide string literals?

Problem

``` 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?

Original source