标准的字符串文字和字符串文字?

character string literal and string literal in standard?

我被这四个词搞糊涂了:

阅读 C Standard 中的这句话:

A character string literal need not be a string (see 7.1.1), because a null character may be embedded in it by a [=10=] escape sequence.

第一部分是什么意思?

一个字符串文字

  • 字符串文字,例如"abc";
  • UTF-8 字符串文字,例如u8"abc";
  • 宽字符串文字,例如L"abc".

来自标准(强调我的):

A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in "xyz". A UTF−8 string literal is the same, except prefixed by u8. A wide string literal is the same, except prefixed by the letter L, u, or U.
....
In translation phase 7, a byte or code of value zero is appended to each multibyte character sequence that results from a string literal or literals. 78)

78) A string literal need not be a string (see 7.1.1), because a null character may be embedded in it by a [=27=] escape sequence.


A string is a contiguous sequence of characters terminated by and including the first null character.

因此字符串文字可能在中间甚至开头也有 [=17=],例如 "a[=18=]b""[=19=]ab"。我认为这就是脚注所说的内容。

一个字符常量是一个用单引号括起来的c-char-sequence(通常是单个字符),可能带有前缀L/u/U.

An integer character constant is a sequence of one or more multibyte characters enclosed in single-quotes, as in 'x'. A wide character constant is the same, except prefixed by the letter L, u, or U.

所以术语不是很对称,IMO。例如。宽字符常量是字符常量的一个特例。然而字符串文字和宽字符串文字都属于字符串文字。