gnustep-dev
[Top][All Lists]
Advanced

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

Re: Problem with +numberWithBool: ?


From: Helge Hess
Subject: Re: Problem with +numberWithBool: ?
Date: Fri, 30 Jan 2004 12:26:44 +0100

On Jan 29, 2004, at 2:12 PM, Richard Frith-Macdonald wrote:
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.

Such an assumption (which is probably not backed by the ObjC "spec") certainly breaks loads of existing code and is IMHO a completely unnecessary and highly error prone.

So ...

if (x)...
is not the same as
if (x == YES)
where x is of type BOOL

Yes, this is not the same, but doesn't relate to BOOL. This is like stating that
  if (x)...
is not the same like
  if (x == 5)
which is true but doesn't relate to the actual question of the "truth" value of an expression.

Indeed BOOL is not an enumeration type of YES and NO (which would back your statement), but YES and NO are regular defines. If it would be defined as

  typedef enum {NO, YES } BOOL;

in objc.h, you would have a point ;-)

which is why I prefer to write code which explicitly compares booleans values with YES or NO.

Hopefully noone else does that. Just fixed a whole lot of OGo code regarding that issue.

Well, I actually try to return YES or NO explicitly do work around IMHO buggy code like the above, eg:
  return [self compare:obj] != 0 ? NO : YES;

Greets,
  Helge
--
OpenGroupware.org => http://www.opengroupware.org/





reply via email to

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