Under C++ or
from C99, how is the less-than operator <
defined for boolean values?
Alternatively, explain the behaviour of
This makes perfect sense. The integral type => bool conversion is effectively b = i != 0
. In order to do the <
comparison it promotes the bool to int by the rule false=>0 and true=>1. In your first case -1
will equate to true, and both will promote to 1 so it's false. Obviously 1 is never less than 0 for the second and third cases, while 0 < 1
in the last case.