数组C ++中每布尔1位 [英] 1 bit per bool in Array C++

查看:62
本文介绍了数组C ++中每布尔1位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bool fp[81];

据我了解,fp应该连续使用ceil(81/8)个字节.

From my understanding fp should use ceil(81/8) bytes because it is in succession.

我正确吗?

我如何证明这一点?

推荐答案

否,缓冲区的大小由实现定义.请参考以下标准中的报价.

No, the sizeof your buffer is implementation defined. Refer the quote from the Standard below.

因此,您可以期望的大小为81 * X,其中X是bool的大小,这是实现的定义.

Therefore the size you can expect is 81 * X where X is the size of bool, which is implementation defined.

$ 5.3.3/1-"sizeof运算符产生其操作数的对象表示形式中的字节数.该操作数可以是未计算的表达式,也可以是带括号的type-id.sizeof运算符不应应用于具有函数或不完整类型的表达式,或者在声明其所有枚举器之前应用于枚举类型,或者应用于此类类型的括号名称,或者应用于指定 一个位域. sizeof(char),sizeof(signed char)和sizeof(unsigned char)为1;这 sizeof应用于任何其他基本类型(3.9.1)的结果是实现定义的. [注意:特别是sizeof(bool)和sizeof(wchar_t)是实现定义的.69)] [注意:有关字节的定义,请参见1.7;有关对象表示的定义,请参见3.9. ]

$5.3.3/1 - "The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is not evaluated, or a parenthesized type-id. The sizeof operator shall not be applied to an expression that has function or incomplete type, or to an enumeration type before all its enumerators have been declared, or to the parenthesized name of such types, or to an lvalue that designates a bit-field. sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1; the result of sizeof applied to any other fundamental type (3.9.1) is implementation-defined. [Note: in particular, sizeof(bool) and sizeof(wchar_t) are implementation-defined.69) ] [Note: See 1.7 for the definition of byte and 3.9 for the definition of object representation. ]

这篇关于数组C ++中每布尔1位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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