C++20 和浮点字节顺序

c++20 and float endianness

短:


跨平台正确处理序列化很困难,浮点字节顺序的奇怪可能性更令人沮丧(诅咒谁决定 ARM 中间端浮点数是个好主意)。不幸的是,我在网上找到的讨论 c++20 特性的文章提到了整数类型,但没有提到浮点数。

标准委员会是否忽略了 float 和 double 类型?
请告诉我没有。

此外,我能找到的文章似乎暗示这些添加只会提供一种检测字节顺序的方法,但不会提供用于在不同编码之间进行转换的标准库函数。如果是这样的话,这似乎并不比标准化预处理器定义更有用。

了解即将推出的 c++20 提案的人能否说明新字节序功能中包含(和不包含)的内容? (...如果您碰巧知道 'why' 会很棒)

Does the c++20 endian proposal only deal with integer types, or does it also give information on float types?

就目前而言,它会告诉您 所有 标量类型是大端还是小端 - 或者,恐怖的是,它们不是,而您正在处理 混合字节序。

所有算术类型都包含在 scalars 中,包括整数和浮点类型。

原因:纯粹是推测,但是在看到大量移植到 C++ 的 C 类型双关版本后进行可移植测试将是一个 为什么

Also, the articles I could find seemed to suggest the additions will only provide a way to detect endianness, but not provide standard library functions for converting between different encodings. If that was the case, this doesn't seem any more useful than just standardizing a preprocessor definition.

您只有一种可移植的方式来检测字节顺序。