Is it safe to memset bool to 0?

前端 未结 4 2015
暖寄归人
暖寄归人 2020-12-01 13:56

Suppose I have some legacy code which cannot be changed unless a bug is discovered, and it contains this code:

bool data[32         


        
4条回答
  •  自闭症患者
    2020-12-01 14:27

    From 3.9.1/7:

    Types bool , char , char16_t , char32_t , wchar_t , and the signed and unsigned integer types are collectively called integral types. A synonym for integral type is integer type . The representations of integral types shall define values by use of a pure binary numeration system.

    Given this I can't see any possible implementation of bool that wouldn't represent false as all 0 bits.

提交回复
热议问题