sizeof(bool) 是否在 C++ 语言标准中定义? [英] Is sizeof(bool) defined in the C++ language standard?

查看:27
本文介绍了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) and sizeof(unsigned char) are 1; the result of sizeof applied to any other fundamental type is implementation-defined. [Note: in particular, sizeof(bool) and sizeof(wchar_t) are implementation-defined.69)]

脚注 69):

sizeof(bool) 不需要为 1.

这篇关于sizeof(bool) 是否在 C++ 语言标准中定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆