Is sizeof(bool) defined in the C++ language standard?(sizeof(bool) 是否在 C++ 语言标准中定义?)
问题描述
我在标准文档中找不到答案.C++ 语言标准是否要求 sizeof(bool) 始终为 1(对于 1 个字节),还是这个大小是实现定义的?
I can't find an answer in the standard documentation. Does the C++ language standard require sizeof(bool) to always be 1 (for 1 byte), or is this size implementation-defined?
推荐答案
sizeof(bool) 是实现定义的,标准特别强调了这一点.
sizeof(bool) is implementation defined, and the standard puts notable emphasis on this fact.
§5.3.3/1,删节:
§5.3.3/1, abridged:
sizeof(char)、sizeof(signed char)和sizeof(unsigned char)为1;sizeof 应用于任何其他基本类型的结果是实现定义的.[注意:特别是 sizeof(bool) 和 sizeof(wchar_t) 是实现定义的.69)]
sizeof(char),sizeof(signed char)andsizeof(unsigned char)are 1; the result ofsizeofapplied to any other fundamental type is implementation-defined. [Note: in particular,sizeof(bool)andsizeof(wchar_t)are implementation-defined.69)]
脚注 69):
sizeof(bool) 不需要为 1.
这篇关于sizeof(bool) 是否在 C++ 语言标准中定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:sizeof(bool) 是否在 C++ 语言标准中定义?
基础教程推荐
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
