number of digits in a hex escape code in C/C++

后端 未结 3 826
挽巷
挽巷 2021-01-07 23:10

I\'m having a dispute with a colleague of mine. She says that the following:

char* a = \"\\x000aaxz\";

will/can be seen by the compiler as

3条回答
  •  半阙折子戏
    2021-01-07 23:51

    §2.13.2/4:

    The escape \xhhh consists of the backslash followed by x followed by one or more hexadecimal digits that are taken to specify the value of the desired character. There is no limit to the number of digits in a hexadecimal sequence. A sequence of octal or hexadecimal digits is terminated by the first character that is not an octal digit or a hexadecimal digit, respectively.

    She is right.

    However, you can terminate it early by eager catenation: the sequence of literals "\x000a" "axz" specifies a single four-character string literal. (2.13.4/3)

    Also note that Unicode uses 21-bit code points; it doesn't stop at 16 bits.

提交回复
热议问题