• 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: Danger: @true and @false aren't considered booleans
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Danger: @true and @false aren't considered booleans


  • Subject: Re: Danger: @true and @false aren't considered booleans
  • From: Roland King <email@hidden>
  • Date: Sun, 19 Aug 2012 12:13:21 +0800


On 19 Aug, 2012, at 11:48 AM, Jens Alfke <email@hidden> wrote:


On Aug 18, 2012, at 8:43 PM, Roland King <email@hidden> wrote:

Interesting. I think I read a discussion about something similar and seem to recall that @YES and @NO do return kCFBooleanTrue and kCFBooleanFalse. Not to suggest for one second that @true and @false shouldn't do the what you suggest, did you try @YES and @NO at all? 

*blink* I didn't even know there were @YES and @NO, although it makes sense that there would be. I'll give them a try. (I wish we could get away from the ancient legacy BOOL/YES/NO stuff, since C's had native booleans for 12 years now, but I digress.)

In that case, the encoding of @true and @false is even weirder, because based on their names, they ought to be "b", the C99/C++ "bool" type.


Thinking about it some more, I may know what's going on here. 

@YES and @NO (as long as you are using a sufficiently recent version of Xcode and operating system, eg 4.4 for OSX 10.8) are specially defined literals which evaluate to kCFBooleanTrue/False, if you're on a version of the toolkit or OS less than that, they just aren't defined at all. @true and @false however are not special literals, so the compiler is just giving you a number literal with the numeric value of true and of false, ie 0 and 1. You get the same effect if you do @(YES) and @(NO) instead of @YES and @NO, the first two end up being NSNumber integer literals, the second two are NSNumber boolean literals. 

This is one instance where the numeric literal syntax possibly violates the principle of least surprise. 
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Danger: @true and @false aren't considered booleans
      • From: Roland King <email@hidden>
References: 
 >Danger: @true and @false aren't considered booleans (From: Jens Alfke <email@hidden>)
 >Re: Danger: @true and @false aren't considered booleans (From: Roland King <email@hidden>)
 >Re: Danger: @true and @false aren't considered booleans (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Danger: @true and @false aren't considered booleans
  • Next by Date: Re: Danger: @true and @false aren't considered booleans
  • Previous by thread: Re: Danger: @true and @false aren't considered booleans
  • Next by thread: Re: Danger: @true and @false aren't considered booleans
  • Index(es):
    • Date
    • Thread