Skip to contentSkip to conversation

Conversion to generic boolean

DISCUSSION [email protected] 1 participant 1 message Aug 29, 2006

lore
Share & tools
lore
#0 lore raw

I have to say, I think <stdbool.h> is a Very Good Thing.

There are actually two stnadard C conventions for boolean return codes:
1) 0 = false, 1 = true
2) 0 = success, -1 = failure (or generally >= 0 and < 0)

I generally like true = success, false = failure, which can require some edits of all the call sites if converting from the second convention.

But in either case, I'd much rather have a function declated "bool" than "int", becuase then I *know* there are only two return values, and nobody has invented a return value of 2 for some reason.

And, as others have noticed, the compiler can optimize using that information, too.

(Conversely, if the convention to use bool where possible is well-established, then if you see "int", you *know* there are more than two possible return values.)

I'm all for just #include <stdbool.h> and use "bool", "true" and "false".