RE: [RFC][PATCH] A generic boolean

From: Shorty Porty
Date: Wed Jul 19 2006 - 23:44:51 EST

Someone showed code like

_Bool foo = 42;

and if we were to make the compiler warn about it that would mean we are
basically trying to change/manipulate the standard (I'm guessing). It's
probably not in the standard because it's such a moot point. However if we
were to use


we'd see it was true. That's because
FALSE == 0
TRUE == !FALSE (i.e. any value that isn't 0)

from the compiler's standpoint. Function that return 'true' for an integer
type (as opposed to a C++ standard-type bool) should be tested like



instead of testing for equality

if(SomeFunction() == TRUE)
if(SomeFunction() == FALSE)

as the former (IMO) is as readable, if not more readable as the latter, and
it's likely to get optimised better. That and someone might give true AND
return a status by returning neither 0 or 1, in which case

if(... == TRUE)

would fail, as TRUE == 1.

And just as a note, you really should read the documentation (at least once)
for any function you use, and therefore know if it returns {FALSE, TRUE, ...
, TRUE} or {OK, ERR1, ERR2, ..., ERRn}

> > If this is the case, then wouldn't "long" be preferable to "int"?

Meh, it's all the same. I don't think 3 wasted CPU cycles is going to worry
anyone too much. Hell, sometimes int IS long, though I might be wrong there.

P.S. First post! Hello everybody.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at