5.3.3 Boolean Types
The compiler supports _Bool
, a type used for holding true
and false values.
The values held by variables of this type are not integers and behave differently in
expressions compared to similar expressions involving __bit
integer types. Integer values converted to a _Bool
type result in 0
(false) if the integer value is 0; otherwise, they result in 1 (true). By comparison, values converted to
the integer __bit
type are truncated to the least significant bit, so
for example, if the value 0x40 was assigned to an object of type __bit
,
that object would be set to zero; whereas assigning that value to a
_Bool
object would set that object to be true.
<stdbool.h>
header defines
true
and false
macros that can be used with
_Bool
types and the bool
macro, which expands to the
_Bool
type. For
example:#include <stdbool.h>
_Bool motorOn;
motorOn = false;