2 Lexical conventions [Lex] 2.13 Literals [lex.literal] 2.13.4 String literals [lex.string] |
2 lexical contract "lexical" 2.13 literal Amount "lexical. Amount of text" 2.13.4 string literal amount "lexical. String" |
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 |
String-text amount: "s-character-sequence opt" L "s-character-sequence opt" S-character-sequence: S-character S-character-sequence S-character S-character: any member in the source character set, except double quote ", backslash/, or newline character escape-sequence Unified character name |
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 a ordinary string literal, also referred to as a narrow string literal. An ordinary string literal have 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 have static storage duration, where n is the size of the Stri ng as defined below, and is initialized with the given characters. |
String literals are enclosed in double quotes and may consist of a sequence of characters (defined in 2.13.2) that begins with a letter L, such as "..." Or L "...". String literals that are not started by L are normal string literals and are also known as narrow string literals. The normal string literal has an array of type "N const char" and a static storage type (3.7), where n is the length of the string defined below and initialized by the given character. A string starting with L, such as L "ASDF", is a wide string literal. The wide string literal has an array of type "N const wchar_t" and a static storage type, where n represents the length of a string as defined below and is initialized by the given character. |
Whether all string literals was distinct (that's, is stored in nonoverlapping objects) is implementation-defined. The effect of attempting to modify a string literal is undefined. |
Whether to keep all string literals independent (that is, stored in objects that are not overlapped) is defined by the compiler. The effect of trying to modify the amount of a string literal is undefined. |
In translation phase 6 (2.1), adjacent narrow string literals is concatenated and adjacent wide string literals is Conca Tenated. If a narrow string literal token is adjacent to a wide string literal token, the behavior is undefined. Characters in concatenated strings is kept distinct. [Example: "/xa" "B" Contains the characters '/xa ' and ' B ' after concatenation (and not the a single hexadecimal character '/xab '). ] |
In the 6th stage of translation (2.1), adjacent narrow string literals are concatenated, and adjacent wide string literals are concatenated. If a narrow string literal tag is adjacent to a wide string literal token, its behavior is undefined. The characters in the concatenated string exist independently. Cases "/xa" "B" After the connection will contain two characters '/xa ' and ' B ' (instead of a single hexadecimal character '/xab '). 】 |
After any necessary concatenation, in translation Phase 7 (2.1), '/0 ' are appended to every string literal so that programs That scan a string can find its end. |
In the 7th stage (2.1), after the necessary connection, '/0 ' is added to each string literal, allowing the program to scan the string to find its end. |
Escape sequences and universal-character-names in string literals has the same meaning as in character literals (2.13 .2), except that the single quote ' was representable either by itself or by the escape sequence/', and the double quote " Shall is preceded by A/. In a narrow string literal, a universal-character-name could 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 th e multibyte encoding of each universal-character-name, plus one for the terminating '/0 '. |
Escape sequences and uniform character names in string literals have the same meaning as in the amount of character literals (2.13.2), except that the single quote ' can represent itself, or be escaped from the sequence/' represented, and the double quote ' must be a/start. In a narrow string literal, a uniform character name may be mapped to more than one char element by multi-byte encoding. The length of the wide string literal is the total number of escape sequences, uniform character names, and other characters, plus a trailing character of L '/0 '. The length of the narrow string literal is the escape sequence and other characters, plus at least one byte number of multibyte encodings per uniform character name, plus a trailing character '/0 '. |
PREV [Lex.fcon] | NEXT [Lex.bool] |
Previous page "lexical. Floating-point Constants" | Next Page "lexical. Boolean Constants" |