编程语言

img lynnboy

2.13.4 - [lex.string] - 【词法.字符串】

发表于2004/10/31 21:34:00  2741人阅读

分类: ISO/IEC 14882:1998

请不要转载本文;请不要以任何形式重新出版,发布本文;请在下载本文 24 小时内将其删除;禁止将本文用于商业目的。

2 Lexical conventions [lex]

2.13 Literals [lex.literal]

2.13.4 String literals [lex.string]

 

2 词法约定 【词法】

2.13 文字量 【词法.文字量】

2.13.4 字符串文字量 【词法.字符串】

 

    string-literal:
        "s-char-sequenceopt"
        L"s-char-sequenceopt"

    s-char-sequence:
        s-char
        s-char-sequence s-char

    s-char:
        any member of the source character set except
            the double-quote ", backslash /, or new-line character
        escape-sequence
        universal-character-name

 

    字符串-文字量:
        "s-字符-序列opt"
        L"s-字符-序列opt"

    s-字符-序列:
        s-字符
        s-字符-序列 s-字符

    s-字符:
        源字符集中的任何成员,除了
            双引号 ",反斜杠 /,或换行字符
        转义-序列
        统一字符名称

 

A string literal is a sequence of characters (as defined in 2.13.2) surrounded by double quotes, optionally beginning with the letter L, as in "..." or L"...". A string literal that does not begin with L is an ordinary string literal, also referred to as a narrow string literal. An ordinary string literal has type "array of n const char" and static storage duration (3.7), where n is the size of the string as defined below, and is initialized with the given characters. A string literal that begins with L, such as L"asdf", is a wide string literal. A wide string literal has type "array of n const wchar_t" and has static storage duration, where n is the size of the string as defined below, and is initialized with the given characters.

 

字符串文字量是由双引号包围的,可能由一个字母 L 开始的字符序列(2.13.2 中定义)组成,比如 "..."L"..."。不是由 L 开始的字符串文字量是普通字符串文字量,也被称为窄字符串文字量。普通字符串文字量具有类型“nconst char 的数组”和静态存储类型(3.7),其中 n 表示如下定义的字符串长度,并由给定的字符初始化。由 L 开始的字符串,如 L"asdf",是宽字符串文字量。宽字符串文字量具有类型“n const wchar_t 的数组”和静态存储类型,其中 n 表示如下定义的字符串长度,并由给定的字符初始化。

 

Whether all string literals are distinct (that is, are stored in nonoverlapping objects) is implementation-defined. The effect of attempting to modify a string literal is undefined.

 

是否保持所有字符串文字量独立(就是说,被不重叠的存储到对象中)是由编译器定义的。尝试修改一个字符串文字量的效果是未定义的。

 

In translation phase 6 (2.1), adjacent narrow string literals are concatenated and adjacent wide string literals are concatenated. If a narrow string literal token is adjacent to a wide string literal token, the behavior is undefined. Characters in concatenated strings are kept distinct. [Example:

    "/xA" "B"

contains the two characters '/xA' and 'B' after concatenation (and not the single hexadecimal character '/xAB'). ]

 

在翻译第 6 阶段(2.1),相邻的窄字符串文字量被连接,相邻的宽字符串文字量被连接。如果窄字符串文字量标记与宽字符串文字量标记相邻,其行为是未定义的。被连接的字符串中的字符是独立存在的。【例:

    "/xA" "B"

在连接后将包含两个字符 '/xA' 和 'B'(而不是单个十六进制字符 '/xAB')。】

 

After any necessary concatenation, in translation phase 7 (2.1), '/0' is appended to every string literal so that programs that scan a string can find its end.

 

翻译第 7 阶段(2.1)中,在必要的连接之后,'/0' 被添加到每个字符串文字量之后,使得扫描字符串的程序可以找到它的结尾。

 

Escape sequences and universal-character-names in string literals have the same meaning as in character literals (2.13.2), except that the single quote ' is representable either by itself or by the escape sequence /', and the double quote " shall be preceded by a /. In a narrow string literal, a universal-character-name may map to more than one char element due to multibyte encoding. The size of a wide string literal is the total number of escape sequences, universal-character-names, and other characters, plus one for the terminating L'/0'. The size of a narrow string literal is the total number of escape sequences and other characters, plus at least one for the multibyte encoding of each universal-character-name, plus one for the terminating '/0'.

 

在字符串文字量中的转义序列和统一字符名称的意义与其在字符文字量(2.13.2)中相同,除了单引号 ' 能够代表自己,或被转义序列 /' 代表,并且双引号 " 必须由一个 / 开始。在窄字符串文字量中,统一字符名称可能被按照多字节编码映射到不只一个 char 元素。宽字符串文字量的长度是转义序列,统一字符名称,以及其他字符,加上一个结尾字符 L'/0' 的总数。窄字符串文字量的长度是转义序列以及其他字符,加上每个统一字符名称的多字节编码的至少一个字节数,再加上一个结尾字符 '/0'

 

PREV [lex.fcon] | NEXT [lex.bool] 上一页 【词法.浮点常量】 | 下一页 【词法.布尔常量】
阅读全文
0 0

相关文章推荐

img
取 消
img