Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC BOOL and boolean c expressions



--- 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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >ObjC BOOL and boolean c expressions (From: Eyal Redler <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.