宽字符字面量前缀 L 是什么意思?
咬文嚼字
1,C/C++标准里没有任何解释
2,Rationale 里只解释了为什么用前缀而不是后缀
那么,L 难道就是 Literal 的首字母?或是 Large,或是 Long ?
何不用 Wide ?据说是重用已有的 long 字面量后缀字母?
有没有确切的说法
大家认为是什么
下面是引文
C99
$6.4.5 String literals
$6.4.5/2
A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in "xyz".A wide string literal is the same, except pre?xed by the letter L.
C++2003
$2.13.2 Character literals
$2.13.2/1
A character literal is one or more characters enclosed in single quotes, as in ’x’, optionally preceded by the letter L, as in L’x’.
$2.13.2/2
A character literal that begins with the letter L, such as L’x’, is a wide-character literal. A wide-character literal has type wchar_t.
Rationale for International Standard Programming Languages C
$6.4.5 String literals
An L prefix distinguishes wide string literals. A prefix rather than a suffix notation was adopted so that a translator can know at the start of the processing of a string literal whether it is dealing with ordinary or wide characters.
[解决办法]
应该是 Large。 如果是Long,就不必再有wide string的叫法,而是直接用 long string了。
记得N年前开始学C时,就因为printf的f确定不了是什么意思,问老师也不知道,只让记住就这样得了。可我那时是有一个字母搞不清意思,就算不影响任何使用,也不能算完,甚至无心继续学,必须搞明白再继续,结果查了很多书才确定,虽然一开始也很自然地想到是那个词,但毕竟是猜测。不过结果这么简单的问题,却花了很大精力,如果不是幸运地在一段全英文资料中看到解释,还不知到什么时候。所以后来渐渐改了这个毛病,能跃过就跃过,不急在一时。再后来学得多了,就更觉得实在不值得了,很多费了功夫的知识,过后可能完全用不上,而生命在不停地走,不能回头的时间当中,你付出的代价,非此即彼,拿了很多不会结果的种子而放弃了另一些能结果的,观赏不错,可到该收获时没收成怎么办。说到时间,至此打住,该干正事了。
[解决办法]
L 是long 的意思,表示加在字符串字面量上表示按两倍的char存储(宽字符)
[解决办法]
是啊,就是定义了这样一个标准。1990年的Rationale for the ANSI C Programming Language这本书有提到这个前缀,但是没有说明原因。另外后续的C++11标准用的是U前缀。
[解决办法]
可能是从long value = 100L;这类用法延伸过来的
[解决办法]
个人猜测应该是long.类似于long int相对于int.
只不过long char/long string不太符合习惯所以又弄了个wchar_t...
再加之c/c++标准不规定数据尺寸,所以这个wchar_t有16位的,有32位的.
而long在c的习惯中应该只是说更大的数据,而不是指32位数据.如:long int,long double.
最终c++11又加上了u8 u U三种确定了长度的字符/字符串,现在真是乱啊
[解决办法]