public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: Conversion to generic boolean
@ 2006-08-29  5:43 linux
  0 siblings, 0 replies; 27+ messages in thread
From: linux @ 2006-08-29  5:43 UTC (permalink / raw)
  To: linux-kernel

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".

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2006-09-04 12:34 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <44EFBEFA.2010707@student.ltu.se>
2006-08-28  9:32 ` Conversion to generic boolean Christoph Hellwig
2006-08-28  9:45   ` Jesper Juhl
2006-08-29 11:39     ` Christoph Hellwig
2006-08-28 10:58   ` Jan Engelhardt
2006-08-28 11:11     ` Bernd Petrovitsch
2006-08-28 12:17     ` Richard Knutsson
2006-08-28 19:15       ` Nicholas Miell
2006-08-28 20:55         ` Richard Knutsson
2006-08-28 21:19           ` Nicholas Miell
2006-08-28 21:55             ` Richard Knutsson
2006-08-29 11:41         ` Christoph Hellwig
2006-08-29 12:17           ` Jan Engelhardt
2006-08-29 13:26             ` Peter Williams
2006-08-29 13:56               ` Jan Engelhardt
2006-08-29 12:48           ` Alan Cox
2006-08-29  0:18   ` Andrew Morton
2006-08-29  1:15     ` Nick Piggin
2006-08-29  5:58       ` Jan Engelhardt
2006-08-31  3:50         ` Dmitry Torokhov
2006-09-03 12:51           ` Pavel Machek
2006-08-29  7:29       ` Anton Altaparmakov
2006-08-29 11:46         ` Christoph Hellwig
2006-08-29 12:18           ` Anton Altaparmakov
2006-08-29 11:45     ` Christoph Hellwig
2006-08-29 14:10       ` Richard Knutsson
2006-08-29 15:47       ` Andrew Morton
2006-08-29  5:43 linux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox