cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: s/bool/int

From: Michael Schuster <michael.schuster_at_oracle.com>
Date: Wed, 26 May 2010 10:33:49 +0200

On 26.05.10 10:04, Tor Arntsen wrote:

> Ok, I'll try from another direction then.. can anyone point to any
> real-life scenarios where using things like
>
> typedef unsigned char bool

no, I cannot (readily, anyway).

I feel this discussion - while you certainly make a point - is putting
emphasis on one aspect only.
What concerns me more is the fact that booleans and integers are
semantically completely different, and the suggested change would
completely lose all information about this difference.

If C (and the current compilers) does not offer the inherent type safety
you're looking for, maybe this calls for some extra programming discipline
to make it as hard as possible to confuse integers and booleans (btw: I've
never seen a char type used as boolean, only integer) - I guess there's
several ways, stringent naming conventions come to mind as one: eg "is_bla"
for a boolean, "item_count" for a counter, etc. Variable names like "a" are
mostly meaningless outside very tight scope.
Avoiding implicit comparisons like
        if (ptr)
for anything non-booelean, and using
        if (ptr != NULL)
is another step in the right direction (and no, that's not my invention,
and yes, I'll readily agree that long exposure to Solaris source has it's
effects ;-)

regards
Michael

-- 
michael.schuster@oracle.com	http://blogs.sun.com/recursion
Recursion, n.: see 'Recursion'
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-05-26