gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with +numberWithBool: ?


From: Alexander Malmberg
Subject: Re: Problem with +numberWithBool: ?
Date: Thu, 29 Jan 2004 15:00:42 +0100

Richard Frith-Macdonald wrote:
> I agree it'll return boolN ... but 2 is not YES
> Booleans in objc can be YES or NO ... this is not the same thing as
> true/false in C/ObjC conditionals where 0 is false and anything
> non-zero is true.

Why would a BOOL be different from any other truth value in c or
objective-c? I have never seen anything that implies that, and to me, it
seems incorrect. In fact, looking at apple's docs for -boolValue, we
see: ""The value returned by this method isn't guaranteed to be one of
YES or NO. A 0 value always means NO or false, but any nonzero value
should be interpreted as YES or true."" .
(http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSNumber.html)

> So ...
> 
> if (x)...
> is not the same as
> if (x == YES)
> where x is of type BOOL
> 
> which is why I prefer to write code which explicitly compares booleans
> values with YES or NO.

But, as this bug shows, you should never explicitly compare with YES.
IMO, doing so is incorrect, or at best extremely pedantic.

- Alexander Malmberg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]