Under C++ or
from C99, how is the less-than operator <
defined for boolean values?
Alternatively, explain the behaviour of
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