| Name | Description | Notes | Source | Availability | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
_Bool |
Boolean type | L | T | Keyword | C99 | C11 | |||||
ATOMIC_ |
Lock-free property of type atomic_ |
? | M | <stdatomic.h> |
C11 | ||||||
atomic_ |
Atomic boolean type | ? | T | <stdatomic.h> |
C11 | ||||||
| Name | Description | Notes | Source | Availability | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
__bool_ |
Indicate availability of boolean type | L | M | <stdbool.h> |
C99 | C11 | |||||
bool |
Boolean type | L | M | T | <stdbool.h> |
C99 | C11 | ||||
false |
Boolean constant ‘false’ | L | M | <stdbool.h> |
C99 | C11 | |||||
true |
Boolean constant ‘true’ | L | M | <stdbool.h> |
C99 | C11 | |||||
A Boolean expression or condition is an expression whose value is interpreted as either true or false. Boolean conditions are expected in several places:
- as the controlling expression in a
whileloop, - as the controlling expression in a
do-whileloop, - as the controlling expression in a
forloop, - as the controlling expression in an
ifstatement, - as the expression in an
#ifor#elifdirective, - as the operand of the logical NOT operator
!, - as the operands of the logical AND operator
&&, - as the operands of the logical OR operator
||.
In these cases, any scalar expression may be given. A real value is first converted to an integer by truncation, and the integer value is compared with 0. If equal, the expression is considered false; otherwise true.
int is
typically used to store or pass a Boolean value, with zero
meaning false, and all other values meaning true. However,
from C99, the native type
_Bool is
defined as a 1-bit unsigned integer type, capable of holding only
0 or 1. Any
value of scalar
type converted to _Bool is
interpreted as 1 if it is
non-zero.
The header <stdbool.h> then
defines several macros to improve readability of Boolean
values and types:
#define bool _Bool #define false 0 #define true 1 #define __bool_true_ 1false_ are_ defined
The ability to #undef bool,
true
or false
is obsolescent. Future standards may make such actions an
error.
In <stdatomic.h>,
atomic_
is an alias for _Atomic _Bool. This type is
lock-free always if
ATOMIC_
is 2, sometimes if 1, and never if 0.