Re: ObjC BOOL and boolean c expressions
Re: ObjC BOOL and boolean c expressions
- Subject: Re: ObjC BOOL and boolean c expressions
- From: Charles Steinman <email@hidden>
- Date: Thu, 30 Aug 2007 23:19:08 -0700 (PDT)
--- Eyal Redler <email@hidden> wrote:
> Hi,
>
> I'm not sure where and when but I recall reading
> something about ObjC
> BOOL type values YES and NO not being the same as
> whet a boolean
> expression might produce.
> I can't recall the exact details but there was some
> kind of gotcha
> related to this. For example, the expression
>
> BOOL myBool=(myInt==1);
>
> might set myBool differently then
>
> BOOL myBool=(myInt==1)?YES:NO;
The two expressions are equivalent. YES is defined as
(BOOL)1, while NO is defined as (BOOL)0.
>
> Or maybe it was that
>
> if (myBool)
> [foo bar];
>
> will perform differently then
> if (myBool==YES)
> [foo bar];
I wouldn't say it will work differently, but it might.
There's no language constraint that says a BOOL can
only be set to YES or NO (though I wouldn't
intentionally set a BOOL to some other value). So if a
method returns a nonzero value that is not 1, if
(myBool) will evaluate to true while if (myBool ==
YES) will evaluate to false.
Cheers,
Chuck
____________________________________________________________________________________
Got a little couch potato?
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden