gpt4 book ai didi

c++ - 使用不适合其相关类型的转义序列

转载 作者:行者123 更新时间:2023-11-27 23:36:23 24 4
gpt4 key购买 nike

我在 C++ Primer 中读到使用大于其最大相关类型的文字是错误的,但在互联网上发现转义序列并非如此。

那么,使用不适合其相关类型的转义序列是错误还是未定义的行为?
例如。 \x1234。假设 Latin-1 字符集并且一个字节是 8 位,这不能放入 char 但仍然是有效的书面文字。

最佳答案

这是 charwchar_t 的实现定义行为,以及 char8_tchar16_tchar32_t[lex.ccon]/8

The escape \ooo consists of the backslash followed by one, two, or three octal digits that are taken to specify the value of the desired character. 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. The value of a character literal is implementation-defined if it falls outside of the implementation-defined range defined for char (for character literals with no prefix) or wchar_­t (for character literals prefixed by L). [ Note: If the value of a character literal prefixed by u, u8, or U is outside the range defined for its type, the program is ill-formed. — end note ]

强调我的


注释是非规范的,但段落 3 , 4 , 和 5来自同一部分的内容覆盖了注释中的文本。

关于c++ - 使用不适合其相关类型的转义序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58922273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com