lkml.org 
[lkml]   [2006]   [Aug]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Conversion to generic boolean
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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-08-29 07:47    [W:0.047 / U:0.348 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site