What is cstdbool in C.

5.15 Boolean value -

A Boolean value was introduced in the C99 standard with _Bool. Fortunately, there is a macro bool for the type _Bool in the header file so that you can use the identifier bool as in C ++. However, you must then include the header file .

Boolean values ​​are elements of a Boolean algebra that can take one of two possible values. This pair of values ​​depends on the application and is either true / false, true / false or 1/0. In C / C ++, the value pair true (for true) and false (for false) can be used, both of which are defined in the header file with the constants 1 and 0. Of course, you can also use the pair 1 and 0 as a decimal value for this:

#include // ... // set switch to true bool b1 = 1; // set switch to false _Bool b2 = 2; // requires bool b3 = true; // true // needs bool b4 = false; // untrue

Whether the truth values ​​true or false are actually present in can be checked with the macro __bool_true_false_are_defined. If this macro returns 1, you can choose between true and false:

if (__bool_true_false_are_defined) print ("true / false are available \ n");


In order not to cause any confusion here, it must be mentioned that the C99 standard has implemented the _Bool type as a real data type. You can only use the macro bool and the two value pairs true and false if you include the header file .


Since some well-known compiler manufacturers such as Microsoft still do not support the C99 standard, I have omitted the _Bool data type or its synonym bool in the examples in the book (in this edition). This data type is useful, for example, when returning functions or when checking logical expressions.

your opinion

How did you like the Openbook? We always look forward to your feedback. Please send us your feedback as an e-mail to [email protected]