C's stdbool.h
adds a #define
for the type _Bool
to bool.
I know a #define
was used instead of a typedef
to allow #undef
-ing for legacy code clashes. But why wasn't bool_t
(to match the other standard types) used in place of bool
? Is the _t
used for typedef
types only?
I ask because the platform I am working on adds a typedef for bool_t
to _Bool
.
EDIT: It's been correctly pointed out that the following is probably opinion based so consider it as only my reason for the primary question above.
So I'm wondering should I use that or continue to use bool
? I kind of like the way the former makes the boolean standard type form match the other standard types.
C introduced the bool
macro (that expands to _Bool
) with the C99 Standard. They probably chose the name bool
instead of bool_t
because C++ in 1998 named their boolean type bool
. In C++98 all integral types (except wchar_t
already in C90) don't use a _t
suffix.
I think you just found that the standard is inconsistent. bool
is not the only type whose name does not have the _t
suffix. Consider, for example, <setjmp.h>
. It defines jmp_buf
which is clearly a typedef
yet does not end in _t
.
I think the main reason why it's not bool_t
is to make it look like it belongs to the family of standard types, int
etc. However, they couldn't name the type bool
due to compatibility purposes so hence the _Bool
.
As for whether you should use bool
or bool_t
I think the question is rather opinion-based and cannot be answered just by using facts. However, I recommend you select one or the other and document that decision well in your coding guidelines.
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