2.6.5 Text and character literals

A character literal is a pair of single quotes enclosing either a single ISO-Latin-1 printing character (excluding single quote) or an escape sequence. The type of a character literal is CHAR.

A text literal is a pair of double quotes enclosing a sequence of ISO-Latin-1 printing characters (excluding double quote) and escape sequences. The type of a text literal is TEXT.

Here are are the legal escape sequences and the characters they denote:

\n newline (linefeed) \f form feed
\t tab \\ backslash
\r carriage return \" double quote
\' single quote \nnn char with code 8_nnn
    \Xnn char with code 16_nn
A \ followed by exactly three octal digits specifies the character whose code is that octal value. A \X followed by exactly two hexadecimal digits specifies the character whose code is that hexadecimal value. The hexadecimal digits are case-insensitive. The 'X' in a hexadecimal escape sequence is case-insensitive. A \ that is not a part of one of these escape sequences is a static error.

A wide character literal has the form W charlit, where charlit is like a character literal, except that an octal escape sequence within must have exactly six octal digits, a hexadecimal escape sequence within must have exactly four hexadecimal digits. and the escape sequence \U followed by exactly six hexadecimal digits is allowed and specifies the Unicode character whose code point has that hexadecimal value. It is a static error if that value lies outside the Unicode code point range. The 'U' in a Unicode escape sequence is case-insensitive. The type of a wide character literal is WIDECHAR. The leading 'W' is case-insensitive.

Similarly, a wide text literal has the form W textlit, where textlit is like a text literal, except any octal or hexadecimal escape sequences within must have exactly six octal or four hexadecimal digits, respectively, and Unicode escape sequences are allowed. Unlike character literals, ordinary text literals and wide text literals both have the type TEXT, differing only in the method of specifying the literal's value. The leading 'W' is case-insensitive.

For example, 'a' and '\'' are valid character literals, ''' is not; "" and "Don't\n" are valid text literals, """ is not.

m3-support@elego.de