Definition of boolean type
Blair P. Houghton
bph at buengc.BU.EDU
Mon Feb 13 10:32:13 AEST 1989
In article <27989 at ucbvax.BERKELEY.EDU> jas at ernie.Berkeley.EDU.UUCP (Jim Shankland) writes:
>
>I agree with Karl Heuer: C would have benefited from a built-in boolean
>type. As is, conscientious programmers will avoid type punning between
>values that are conceptually boolean with those that are conceptually
>integers (though as far as C is concerned, of course they're both integers.)
Low-sophistication point-of-interest, approx. 20 mills in value:
You can be conscientious if, when unsure of the return value, and you _like_
having true==1 and false==0, then say
boolfoo = !!expr_returning_funny_bools;
which, according to my KnR, should never ever give any boolfoo other
than 0 or 1, even if the expr has a dozen different values for true.
(See the description of the '!' op. I think it's around page 187 of ed. 1.)
--Blair
"!!(But I can't be sure...)"
More information about the Comp.lang.c
mailing list