My question regarding underscores in names is partly answered here, but either the answer is incomplete or I do not fully understand it.
Sect. 2.14.8.7 of the C++11 standard declares this literal operator as an example:
long double operator "" _w(long double);
Besides declaring the operator, the standard and its example do two further things that, if viewed separately, each make sense:
_w with an underscore; andMy question has two parts:
_w is not an identifier, or the identifier _w is not a name, or ... well, I'm confused._w is okay, then is the capitalized _W okay, too -- as in 60.0_W, meaning 60.0 watts? Or is the preprocessor likely to mishandle the capitalized version?Undoubtedly like you, I am not in the habit of starting global names with underscores, a habit the standard's sect. 17.6.4.3.2.1 explicitly seems to deprecate. Therefore, if you can cast some additional light on the matter of underscores, names and literal operators, the light would be appreciated.
Alright, I checked back with Richard Smith from the Clang team, and the _W part in your literal operator is indeed not a reserved identifier and/or name and it is also a seperate preprocessor token which will get expanded if it names a macro. This is in accordance with the standard subclauses 2.5, where an identifier is a preprocessor-token, and 2.2 which has macro expansion as part of phase 4, before preprocessor-tokens are replaced with just tokens of the language grammar, which happens in phase 7.
He also mentioned that, since the Portland meeting of the committee, you can say operator""_W, which will prevent macro expansion, since the _W is not a single identifier anymore. Clang trunk already implements this and compiles the following snippet:
#define _W _x
int operator""_W(unsigned long long){ return 42; }
int main(){
int i = 1337_W;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With