The C11 standard defines the _Bool
type (6.2.5.2) as a standard unsigned integer type (6.2.5.6) and as I read the standard, _Bool
is then also an arithmetic type (6.2.5.18 via 6.2.5.7 and 6.2.5.17).
Furthermore, it is specified that for +
and -
"both operands shall have arithmetic type, or one operand shall be a pointer to a complete object type and the other shall have integer type" (6.5.6.2).
However, about the result I can only see "The result of the binary + operator is the sum of the operands" (6.5.6.5) and "The result of the binary - operator is the difference resulting from the subtraction of the second operand from the first" (6.5.6.6). For two booleans, "sum" may be interpreted as logical OR, but I do not think "subtraction" has a well-defined meaning.
So the question is: is the result of a+b
and a-b
(where a
and b
have type _Bool
) undefined behavior in C11 or does the standard clearly define the result of these operations (if so, where?)?
Note: maybe the standard just sees _Bool
as an integer with very small range. In that case, I would expect true
+true
to be 0
(1 + 1 modulo 2). However, GCC says 1.