gpt4 book ai didi

c++ - 在 C++ 标准中哪里说 sizeof(wchar_t) <= sizeof(long) 和 sizeof(bool) <= sizeof(long)?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:36:55 27 4
gpt4 key购买 nike

先生。 Stroustrup 在他的新书(TCPL 第 4 版)第 149 页写下了以下内容

1 <= sizeof(wchar_t) <= sizeof(long)

我在标准中找不到任何支持上面最后一个不等式的内容。我可以对 sizeof(bool) <= sizeof(long) 说同样的话.

编辑:在3.9.1p5你会发现:

Type wchar_t shall have the same size, signedness, and alignment requirements (3.11) as one of the other integral types, called its underlying type.

支持不平等

sizeof(wchar_t) <= sizeof(long long)

但不是

sizeof(wchar_t) <= sizeof(long)

但是我找不到任何可以证实的东西

sizeof(bool) <= sizeof(long)

最佳答案

很难想象 sizeof(wchar_t)>N && sizeof(long)<=N任何 N 值的实现,更不用说任何人都会考虑使用 wchar_t 的实现了.也就是说:

其实我觉得不对。 4.5 “积分促销”p2 明确允许以下可能性:

2. A prvalue of type char16_t, char32_t, or wchar_t (3.9.1) can be converted to a prvalue of the first of the following types that can represent all the values of its underlying type: int, unsigned int, long int, unsigned long int, long long int, or unsigned long long int. If none of the types in that list can represent all the values of its underlying type, a prvalue of type char16_t, char32_t, or wchar_t can be converted to a prvalue of its underlying type.

和 5.3.3 "sizeof"p1 明确保留了实现定义的实际大小:

1. [...] The result of sizeof applied to any other fundamental type (3.9.1) is implementation-defined. [ *Note: in particular, sizeof(bool), sizeof(char16_t), sizeof(char32_t), and sizeof(wchar_t) are implementation-defined.* 76 — end note ] [ Note: See 1.7 for the definition of byte and 3.9 for the definition of object representation. — end note ]

虽然 5.3.3 足以让相对大小受到质疑,但 wchar_t 的规范可能性在任何标准类型中都无法表示,我认为这是毫无疑问的。

关于c++ - 在 C++ 标准中哪里说 sizeof(wchar_t) <= sizeof(long) 和 sizeof(bool) <= sizeof(long)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20552491/

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