Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the prefix L"..." stand for in GCC C without #including wchar?

Tags:

c

types

That is, why does unsigned short var= L'ÿ' work, but unsigned short var[]= L"ÿ"; does not?

like image 628
Dervin Thunk Avatar asked Dec 01 '25 08:12

Dervin Thunk


2 Answers

L'ÿ' is of type wchar_t, which can be implicitly converted into an unsigned short. L"ÿ" is of type wchar_t[2], which cannot be implicitly converted into unsigned short[2].

like image 97
Chris Jester-Young Avatar answered Dec 04 '25 02:12

Chris Jester-Young


L is the prefix for wide character literals and wide-character string literals. This is part of the language and not a header. It's also not GCC-specific. They would be used like so:

wchar_t some_wchar = L'ÿ';
wchar_t *some_wstring = L"ÿ"; // or wchar_t some_wstring[] = L"ÿ";

You can do unsigned short something = L'ÿ'; because a conversion is defined from wchar_t to short. There is not such conversion defined between wchar_t* and short.

like image 27
Steve M Avatar answered Dec 04 '25 01:12

Steve M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!