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

查看:198
本文介绍了C ++语言标准中是否定义了sizeof(bool)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标准文档中找不到答案. 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.

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

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