doubles used as booleans

Henry Spencer henry at utzoo.uucp
Sat Apr 1 03:25:05 AEST 1989


In article <8269 at xanth.cs.odu.edu> kremer at cs.odu.edu (Lloyd Kremer) writes:
>	Can a double be used directly as a boolean?

Any "scalar" type -- an arithmetic or pointer type -- can.

>	The optimizing in the compilers I was using was minimal, and I
>	found that substitutions such as 'if(i)' instead of 'if(i != 0)',
>	and 'if(!n)' in place of 'if(n == 0)' produced smaller code for
>	integral types...

Talk about lazy compilers...

>	[compilers that balk at doing implicit comparison against 0 for double]
>	... Would these compilers be officially broken by today's standards?

Yes.  They've been officially broken by the prevailing de-facto standards
all along, as well.
-- 
Welcome to Mars!  Your         |     Henry Spencer at U of Toronto Zoology
passport and visa, comrade?    | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list