[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with +numberWithBool: ?
From: |
Pascal J . Bourguignon |
Subject: |
Re: Problem with +numberWithBool: ? |
Date: |
Sat, 31 Jan 2004 00:04:45 +0100 |
Richard Frith-Macdonald writes:
>
> On 30 Jan 2004, at 11:26, Helge Hess wrote:
>
> > 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")
>
> I have noticed that when you say 'probably' you seem to mean 'I haven't
> checked' :-)
>
> Page 178 of the NeXTstep reference, section headed Defined Types ...
>
> 'BOOL A boolean value, either YES or NO'
>
> I'm sure I've seen arguments about this before - I judged the
> consensus to be that the BOOL type is intended to be boolean, and
> the fact that it's stored as a char is an implementation detail.
>
> In practice, it matters little as long as you are consistent ... and
> are careful in cases where you interface to unknown code. Sometimes
> a problem with categories. Nevertheless, I'd consider it very poor
> programming to return anything other than YES or NO from a method
> declared to return BOOL.
It's a C (or Objective-C) question: does a==b (or a<b, etc) return 0/1
or 0/possibly anything else than 0 ?
On 680x0 processors, the instructions that build boolean values give 0
and 0xff ((char)(-1)). All C compilers I've see on these processors
always take care to mask it off to 0/1.
I don't have my ANSI-C references at hand, but if it's said that
boolean producing operators always return 0 or 1, then there is no
problem, returning a boolean expression will return a BOOL (or a
bool).
In any case, that's one more reason why it's better to write
if(condition) rather than if(condition==YES).
--
__Pascal_Bourguignon__ http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), (continued)
- Re: [RFA]: BOOL coding standards (Was: Problem with+numberWithBool: ?), Alexander Malmberg, 2004/01/31
- Re: Problem with +numberWithBool: ?, Alexander Malmberg, 2004/01/30
- Re: Problem with +numberWithBool: ?, Nicola Pero, 2004/01/30
- Re: Problem with +numberWithBool: ?, Alexander Malmberg, 2004/01/30
- Re: Problem with +numberWithBool: ?, Philippe C.D. Robert, 2004/01/30
- Re: Problem with +numberWithBool: ?, Pascal J . Bourguignon, 2004/01/30
- Re: Problem with +numberWithBool: ?, Richard Frith-Macdonald, 2004/01/30
- Re: Problem with +numberWithBool: ?,
Pascal J . Bourguignon <=
- Re[2]: Problem with +numberWithBool: ?, Manuel Guesdon, 2004/01/30