标准的字符串文字和字符串文字?
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。例如。宽字符常量是字符常量的一个特例。然而字符串文字和宽字符串文字都属于字符串文字。
我被这四个词搞糊涂了:
字符串文字
字符常量
字符串文字。
多字节字符序列
阅读 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 letterL
,u
, orU
.
....
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 letterL
,u
, orU
.
所以术语不是很对称,IMO。例如。宽字符常量是字符常量的一个特例。然而字符串文字和宽字符串文字都属于字符串文字。