相邻的字符和字符串文字标记 [英] Adjacent character and string literal tokens
问题描述
众所周知,在C语言中您可以编写"a" "b"
并获取"ab"
.在C11
标准中对此进行了讨论:
It's a familiar fact that in C you can write "a" "b"
and get "ab"
. This is discussed in the C11
standard:
在翻译阶段6中,将由任意相邻字符序列和相同前缀的字符串文字标记指定的多字节字符序列连接为单个多字节字符序列.
In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and identically-prefixed string literal tokens are concatenated into a single multibyte character sequence.
短语"character and ..."似乎表明您可以通过编写'a' "b"
来获得相同的结果,但是我从来没有遇到过这种用法,GCC和Microsoft编译器都拒绝了它.我想念什么吗?
The phrase "character and..." would seem to suggest you can get the same results by writing 'a' "b"
, but I've never come across that usage and GCC and the Microsoft compiler both reject it. Am I missing something?
推荐答案
不,也许我们在此处所作的陈述中得到了错误的含义.
No, maybe we're getting a wrong meaning out of the statement made there.
让我引用C11
的第5.1.1.2章,翻译阶段的第6段,
Let me quote from C11
, chapter §5.1.1.2, Translation phases, paragraph 6,
- 相邻的字符串文字标记是串联在一起的.
在这里,我们在char
和 string 文字之间没有任何混淆,只清楚地提到了 string 文字.
Here, we don't have any confusion between char
and string literals, it's clearly mentioned about string literals only.
这篇关于相邻的字符和字符串文字标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!