C ++语言标准中是否定义了sizeof(bool)? [英] Is sizeof(bool) defined in the C++ language standard?
问题描述
我在标准文档中找不到答案. 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 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)
不必为1.
这篇关于C ++语言标准中是否定义了sizeof(bool)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!