Engineered bool compares equal to both true and false, why?

后端 未结 5 1201
暖寄归人
暖寄归人 2020-12-10 11:04

The example bellows compiles, but the output is rather strange :

#include 
#include 

struct A
{
    int a;
    char b;
    bo         


        
5条回答
  •  渐次进展
    2020-12-10 11:45

    I thing I found the answer. 3.9.1-6 says :

    Values of type bool are either true or false.42) [Note: there are no signed, unsigned, short, or long bool types or values. ] As described below, bool values behave as integral types. Values of type bool participate in integral promotions (4.5).

    Where the note 42 says :

    42) Using a bool value in ways described by this International Standard as ‘‘undefined,’’ such as by examining the value of an uninitialized automatic variable, might cause it to behave as if it is neither true nor false.

提交回复
热议问题