我在标准文档中找不到答案。 C++ 语言标准是否要求 sizeof(bool)
始终为 1(对于 1 个字节),还是这个大小是实现定义的?
最佳答案
sizeof(bool)
是实现定义的,标准特别强调了这一事实。
§5.3.3/1,删节:
sizeof(char)
,sizeof(signed char)
andsizeof(unsigned char)
are 1; the result ofsizeof
applied to any other fundamental type is implementation-defined. [Note: in particular,sizeof(bool)
andsizeof(wchar_t)
are implementation-defined.69)]
脚注 69):
sizeof(bool)
is not required to be 1.
关于c++ - sizeof(bool) 是否在 C++ 语言标准中定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4897844/