Any time I had the need of a Boolean type I was told to either create one, or better yet, use stdbool.h
.
Since stdbool.h
uses typedef bool _Bool
, is there a reason to use the header instead just using type _Bool
? Is it just for the additional macros (/* #define true 1 #define false 0 */
)?
The obvious type to add into the language was bool
. But unfortunately, plenty of code was written that included bool
in other shapes and forms. Recall that support for a boolean type was added only in C99.
So the C language committee had no choice but to pull out a reserved identifier for it (_Bool
). But, since the obvious choice of type name is still the same, stdbool.h
was added to allow users the obvious name. That way, if your code didn't have a home-brewed bool
, you could use the built in one.
So do indeed use stdbool.h
if you aren't bound to some existing home-brewed bool
. It will be the standard type, with all the benefits that type brings in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With