Is there any downside to using
typedef char bool;
enum boolean { false, true };
in C to provide a semantic boolean type?
The downside of typedef char bool;
is that if you compile with a C99 implementation and happen to include
, this ends up as typedef char _Bool;
, which is wrong. Also, if you ever tried to compile the code as C++, you'd have issues (that's not necessarily a problem, but it could be).
It would probably better either to use
if your implementation provides one or to use a different name for the type, like BOOL
.