Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 06 Dec 2011 15:55:16 +0100
From:      =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
To:        Rick Macklem <rmacklem@uoguelph.ca>
Cc:        Zack Kirsch <zack@FreeBSD.ORG>, mdf@FreeBSD.ORG, David Schultz <das@FreeBSD.ORG>, John Baldwin <jhb@FreeBSD.ORG>, freebsd-arch@FreeBSD.ORG
Subject:   Re: Use of bool / stdbool.h in kernel
Message-ID:  <86borlda23.fsf@ds4.des.no>
In-Reply-To: <1697386241.723355.1322748438341.JavaMail.root@erie.cs.uoguelph.ca> (Rick Macklem's message of "Thu, 1 Dec 2011 09:07:18 -0500 (EST)")
References:  <1697386241.723355.1322748438341.JavaMail.root@erie.cs.uoguelph.ca>

next in thread | previous in thread | raw e-mail | index | archive | help
Rick Macklem <rmacklem@uoguelph.ca> writes:
> If this is added, would the style gods approve of the following:
>
> (A) bool test_func();
>
>     if (test_func())
>            ...
>
> instead of:
>
> (B) int test_func();
>
>     if (test_func() !=3D 0)
>            ...

Part of the problem is that the opposite semantics are widely used,
i.e. 0 indicates success and non-zero indicates failure, possibly with
different non-zero values having different specific meanings.  There are
also cases (such as open() and socket()) where >=3D 0 indicates success
while < 0 indicates failure.  Therefore, an explicit comparison is
preferred, except for functions like isspace() and the like whose names
clearly indicate that they are predicates.

DES
--=20
Dag-Erling Sm=C3=B8rgrav - des@des.no



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86borlda23.fsf>