Re: Conversion to generic boolean
From: linux
Date: Tue Aug 29 2006 - 01:40:48 EST
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".
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/