character string literal and string literal in standard?

I am confused by these four terms:

  • character string literal

  • character constants

  • string literal.

  • multibyte character sequence

  • And reading this quote in C Standard:

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

    What is meant by the first part ?


    A string-literal is

  • either a character string literal, eg "abc" ;
  • or UTF-8 string literal, eg u8"abc" ;
  • or wide string literal, eg L"abc" .
  • From the standard (emphasis mine):

    A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in "xyz" . A UTF−8 string literal is the same, except prefixed by u8. A wide string literal is the same, except prefixed by the letter L , u , or U .
    ....
    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. 78)

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


    A string is a contiguous sequence of characters terminated by and including the first null character .

    So a string literal may have also in the middle or even at the beginning, for instance "ab" or "ab" . I think this is what the footnote is saying.

    A character constant is a c-char-sequence (usually a single character) in single quotes, with a possible prefix L / u / U .

    An integer character constant is a sequence of one or more multibyte characters enclosed in single-quotes, as in 'x' . A wide character constant is the same, except prefixed by the letter L , u , or U .

    So the terminology is not very symmetric, IMO. Eg wide character constant is a particular case of character constant. However both character string literal and wide string literal belong to string literals.

    链接地址: http://www.djcxy.com/p/38614.html

    上一篇: 当最后一个字符是`\`时``String.raw`

    下一篇: 字符串文字和字符串文字在标准?