• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ObjC BOOL and boolean c expressions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: ObjC BOOL and boolean c expressions
      • From: John Stiles <email@hidden>
References: 
 >ObjC BOOL and boolean c expressions (From: Eyal Redler <email@hidden>)

  • Prev by Date: Re: Finding definitions
  • Next by Date: Re: The magic of Key Value Coding and Key Value Observing
  • Previous by thread: ObjC BOOL and boolean c expressions
  • Next by thread: Re: ObjC BOOL and boolean c expressions
  • Index(es):
    • Date
    • Thread