gpt4 book ai didi

具有 UTF-8 执行字符集的 C++11 字 rune 字 '\xC4' 标准类型?

转载 作者:搜寻专家 更新时间:2023-10-31 01:50:28 28 4
gpt4 key购买 nike

考虑一个具有 UTF-8 执行字符集的 C++11 编译器(并且符合要求 char 类型为有符号 8 位字节的 x86-64 ABI) .

字母 Ä(元音变音)具有 0xC4 的 unicode 代码点,并且具有 {0xC3, 0x84} 的 2 个代码单元 UTF-8 表示>

编译器为字 rune 字 '\xC4' 分配了一个 int 类型,值为 0xC4

编译器是否符合标准和 ABI 标准?你的理由是什么?

C++11标准的相关引述:

2.14.3.1

An ordinary character literal that contains a single c-char has type char, with value equal to the numerical value of the encoding of the c-char in the execution character set. An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal has type int and implementation-defined value.

2.14.3.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. The value of a character literal is implementation-defined if it falls outside of the implementation-defined range defined for char

最佳答案

§2.14.3 paragraph 1无疑是(C++11)标准中的相关文字。但是,原文中存在一些缺陷,最新版本包含以下文字,强调:

A multicharacter literal, or an ordinary character literal containing a single c-char not representable in the execution character set, is conditionally-supported, has type int, and has an implementation-defined value.

虽然这已被接受为 defect ,它实际上并不构成任何标准的一部分。但是,它只是一个建议,我怀疑许多编译器会实现它。

关于具有 UTF-8 执行字符集的 C++11 字 rune 字 '\xC4' 标准类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15057233/

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