Ordering of boolean values

后端 未结 7 1748
醉酒成梦
醉酒成梦 2021-02-18 17:02

Under C++ or from C99, how is the less-than operator < defined for boolean values?

Alternatively, explain the behaviour of

7条回答
  •  执念已碎
    2021-02-18 17:46

    For C++ just false < true

    For C is more difficult to answer. I see

    typedef char _Bool; /* For C compilers without _Bool */ in my stdbool.h

    Seems, that if compiler support _Bool , it works as in C++ and automatically converts to 0/1, but if not it should work as char and it'll be b < true, b < false if char is signed

    For me (int)(bool) -1 is 1 even in C, so bool is defined as not char

提交回复
热议问题