Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this: L"DLGCTRL_"L#dialog_control_id

I've found this in some C++_11 code:

L"DLGCTRL_"L#dialog_control_id

What is a "L#" here? There is no # operator or concatenation so. Yes, there is nothing between the " and the L. How can be this allowed?

I get the error:

error C3688: invalid literal suffix 'L'; literal operator or literal operator template 'operator ""L' not found

I have Visual Studio 2015 and 2017 on Windows 10. It compiles normally on C++98 or 00

like image 517
user4576528 Avatar asked Dec 15 '25 05:12

user4576528


1 Answers

I assume this occurs inside a preprocessor macro otherwise the question makes no sense at all, e.g.:

#define X(dialog_control_id)  L"DLGCTRL_"L#dialog_control_id

where it is intended that X(foo) expands to L"DLGCTRL_foo".


The code should be:

#define X(dialog_control_id)  L"DLGCTRL_" #dialog_control_id

There are several problems in the original code:

  • L# is not allowed in ISO C++, it is an extension of the Microsoft preprocessor to produce a wide string literal.
  • In the C++11 preprocessor, a letter directly after a closing quote (without whitespace in between) is tokenized as a user-defined string literal.
  • The last L was never necessary anyway, because a wide string literal can be concatenated with a narrow string literal (producing a wide string literal)
like image 178
M.M Avatar answered Dec 16 '25 21:12

M.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!