Emulation of Boolean elements in C can be done as follows:
int success; success = (errors == 0 && count > 0); if(success) ...
With stdbool.h enabled, the following can be:
bool success; success = (errors == 0 && count > 0) ? true : false; if(success) ...
From what I understand, logical and comparison operators should return either 1 or 0. In addition, stdbool.h constants must be defined so that true == 1 and false == 0 .
So the following should work:
bool success; success = (errors == 0 && count > 0); if(success) ...
And it works on compilers with which I tested it. But can this be considered portable code? (Assume stdbool.h exists)
Is the situation different for C ++ compilers since bool is an internal type?
source share