### 2 词法约定 【词法】

#### 2.13.2 字符文字量 【词法.字符常量】

character-literal:
'c-char-sequence'
L'c-char-sequence'

c-char-sequence:
c-char
c-char-sequence c-char

c-char:
any member of the source character set except
the single-quote ', backslash /, or new-line character
escape-sequence
universal-character-name

escape-sequence:
simple-escape-sequence
octal-escape-sequence

simple-escape-sequence: one of
/' /" /? //
/a /b /f /n /r /t /v

octal-escape-sequence:
/ octal-digit
/ octal-digit octal-digit
/ octal-digit octal-digit octal-digit

/x hexadecimal-digit

字符-文字量:
'c-字符-序列'
L'c-字符-序列'

c-字符-序列:
c-字符
c-字符-序列 c-字符

c-字符:
源字符集中的任何字符，除了
单引号 '，反斜杠 /，或换行字符
转义-序列
统一字符名称

转义-序列:
简单-转义-序列
八进制-转义-序列
十六进制-转义-序列

简单-转义-序列: 下列之一
/' /" /? //
/a /b /f /n /r /t /v

八进制-转义-序列:
/ 八进制-数字
/ 八进制-数字 八进制-数字
/ 八进制-数字 八进制-数字 八进制-数字

十六进制-转义-序列:
/x 十六进制-数字
十六进制-转义-序列 十六进制-数字

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'. A character literal that does not begin with L is an ordinary character literal, also referred to as a narrow-character literal. An ordinary character literal that contains a single c-char has type char, with value equal to the numerical value of the encoding of the c-char in the execution character set. An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal has type int and implementation-defined value.

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.23) The value of a wide-character literal containing a single c-char has value equal to the numerical value of the encoding of the c-char in the execution wide-character set. The value of a wide-character literal containing multiple c-chars is implementation-defined.

L 开始的字符文字量是宽字符文字量，如 L'x'。宽字符文字量具有类型 wchar_t23) 包含一个 c-字符的宽字符文字量的值与执行宽字符集中该 c-字符的编码数值相等。包含多个 c-字符的宽字符文字量的值由实现定义。

Certain nongraphic characters, the single quote ', the double quote ", the question mark ?, and the backslash /, can be represented according to Table 5.

#### Table 5 - escape sequences

new-line NL(LF) /n
horizontal tab HT /t
vertical tab VT /v
backspace BS /b
carriage return CR /r
form feed FF /f
backslash / //
question mark ? /?
single quote ' /'
double quote " /"
octal number ooo /ooo
hex number hhh /xhhh

The double quote " and the question mark ?, can be represented as themselves or by the escape sequences /" and /? respectively, but the single quote ' and the backslash / shall be represented by the escape sequences /' and // respectively. If the character following a backslash is not one of those specified, the behavior is undefined. An escape sequence specifies a single character.

#### 表格 5 - 转义序列

The escape /ooo consists of the backslash followed by one, two, or three octal digits that are taken to specify the value of the desired character. The escape /xhhh consists of the backslash followed by x followed by one or more hexadecimal digits that are taken to specify the value of the desired character. There is no limit to the number of digits in a hexadecimal sequence. A sequence of octal or hexadecimal digits is terminated by the first character that is not an octal digit or a hexadecimal digit, respectively. The value of a character literal is implementation-defined if it falls outside of the implementation-defined range defined for char (for ordinary literals) or wchar_t (for wide literals).

A universal-character-name is translated to the encoding, in the execution character set, of the character named. If there is no such encoding, the universal-character-name is translated to an implementation-defined encoding. [Note: in translation phase 1, a universal-character-name is introduced whenever an actual extended character is encountered in the source text. Therefore, all extended characters are described in terms of universal-character-names. However, the actual compiler implementation may use its own native character set, so long as the same results are obtained. ]

23) They are intended for character sets where a character does not fit into a single byte.

23) 它们由不能用单个字节表达字符的字符集利用。

PREV [lex.icon] | NEXT [lex.fcon] 上一页 【词法.整型常量】 | 下一页 【词法.浮点常量】

0 0