gpt4 book ai didi

c++ - u'\U0001ABCD' 是否具有实现定义的值或格式错误?

转载 作者:太空狗 更新时间:2023-10-29 23:18:33 24 4
gpt4 key购买 nike

标准似乎对 char16_t 字面值有两种不同的响应,其中包含一个不能用 char16_t 表示的字符。首先,如果代码点值不能用 16 位表示(即它不在基本多语言平面 (BMP) 中),则程序格式错误 (§2.14.3/2):

The value of a char16_t literal containing a single c-char is equal to its ISO 10646 code point value, provided that the code point is representable with a single 16-bit code unit. (That is, provided it is a basic multi-lingual plane code point.) If the value is not representable within 16 bits, the program is ill-formed.

由于 \U0001ABCD 是单个 c-char1 但不在 BMP 中,因此包含它的程序格式错误。

好的,但稍后在同一章中,它说如果该值超出 char16_t 的实现定义范围,则文字具有实现定义的值(§2.14.3/4):

The value of a character literal is implementation-defined if it falls outside of the implementation-defined range defined for [...] char16_t (for literals prefixed by ’u’) [...]

由于 char16_t 的实现定义范围必须至少为 16 位(以便能够存储整个 BMP),我们已经知道该程序对于落在在那个范围之外。为什么该标准费心给它一个实现定义的值?

1 产生式规则是c-char -> universal-character-name -> \U 六边形 六边形

最佳答案

根据 2.14.3/2,程序格式错误,这意味着必须诊断错误。不需要进一步分析,因为不需要实现来完成编译或生成可执行文件。文字可能被认为仍然具有值(value),但这并不重要。

(虽然实现允许编译和执行格式错误的程序。所以我想在那种情况下,字 rune 字仍然被指定为具有值这一事实很重要。)

关于c++ - u'\U0001ABCD' 是否具有实现定义的值或格式错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13554914/

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