6.4.5 String literals

Previous Table of Contents

889

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

890 A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in "xyz".

891 A wide string literal is the same, except prefixed by the letter L.

892 The same considerations apply to each element of the sequence in a character string literal or a wide string literal as if it were in an integer character constant or a wide character constant, except that the single-quote ' is representable either by itself or by the escape sequence \', but the double-quote " shall be represented by the escape sequence \".

893 In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and wide string literal tokens are concatenated into a single multibyte character sequence.

894 If any of the tokens are wide string literal tokens, the resulting multibyte character sequence is treated as a wide string literal;

895 otherwise, it is treated as a character string literal.

896 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.66)

897 The multibyte character sequence is then used to initialize an array of static storage duration and length just sufficient to contain the sequence.

898 For character string literals, the array elements have type char, and are initialized with the individual bytes of the multibyte character sequence;

899 for wide string literals, the array elements have type wchar_t, and are initialized with the sequence of wide characters corresponding to the multibyte character sequence, as defined by the mbstowcs function with an implementation-defined current locale.

900 66) A character string literal need not be a string (see 7.1.1), because a null character may be embedded in it by a \0 escape sequence.

901 The value of a string literal containing a multibyte character or escape sequence not represented in the execution character set is implementation-defined.

902 It is unspecified whether these arrays are distinct provided their elements have the appropriate values.

903 If the program attempts to modify such an array, the behavior is undefined.

904 EXAMPLE This pair of adjacent character string literals


        "\x12" "3"

produces a single character string literal containing the two characters whose values are '\x12' and '3', because escape sequences are converted into single members of the execution character set just prior to adjacent string literal concatenation.

905 Forward references: common definitions <stddef.h> (7.17), the mbstowcs function (7.20.8.1).

Next

Created at: 2005-06-29 02:18:58 The text from WG14/N1124 is copyright © ISO