typedefs, etc. - (nf)
Morris Keesan
keesan at bbncca.ARPA
Wed Jan 4 01:01:55 AEST 1984
-----------------------------------
>ucbesvax!turner Dec 30 03:26:00 1983
>Re: returning crafty boolean expressions
> typedef int BOOL; /* ?! */
>That's not what I do! I have (in ~turner/include/macros.h):
> typedef enum { FALSE, TRUE } bool;
>With this bool-type, the following causes a type-clash on return value warning:
> bool yes( )
> {
> return getchar( ) == 'y';
> }
>I would have to (and am willing to) say, instead:
> bool yes( )
> {
> if (getchar( ) == 'y')
> return TRUE;
> else
> return FALSE;
> }
>>>>>>>>>
I question the utility of a 'bool' type which generates type-clashes
with boolean expressions. However, if you insist on using it, do you object
to
return( (bool)(getchar() == 'y') );
? This avoids the type-clash warning, and is guaranteed to work.
Saying
if( getchar() == 'y' ) return TRUE; else return FALSE;
is only one step away from
if( (getchar() == 'y') == TRUE ) return TRUE; else return FALSE;
and equally silly. The whole point of boolean types/values is that they reflect
the values which can be held by boolean expressions.
--
Morris M. Keesan
{decvax,linus,wjh12}!bbncca!keesan
keesan @ BBN-UNIX.ARPA
More information about the Comp.unix
mailing list