• 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: Good idea/bad idea?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Good idea/bad idea?


  • Subject: Re: Good idea/bad idea?
  • From: Sean McBride <email@hidden>
  • Date: Thu, 24 Apr 2014 13:02:10 -0400
  • Organization: Rogue Research Inc.

On Thu, 24 Apr 2014 09:44:42 -0700, Jens Alfke said:

>> NSString x;
>> x = (x) ?: @"yo";
>
>It’s not a terrible idea; I use this pattern a lot.
>
>The ternary operator doesn’t just work on integers. It’s like “if”, it
>takes any expression that can be interpreted as a boolean. For a pointer
>the test is implicitly the same as “x != nil”. The example you gave is
>exactly equivalent to
>	if (x)
>		x = x;
>	else
>		x = @“yo”;

Exactly equivalent if 'x' is a simple thing like a pointer/integer, as being discussed.

But as discussed here:

<http://en.wikipedia.org/wiki/?:#C>

beware the case of x being an expression and whether it gets evaluated once or more times.

Also, the "a = x ? : y;" form is not C, it is a GNU extension.

Cheers,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada

_______________________________________________

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


References: 
 >Good idea/bad idea? (From: Alex Zavatone <email@hidden>)
 >Re: Good idea/bad idea? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: IOKit / OSX: How can I distinguish between "real hard disk" and mounted images?
  • Next by Date: Re: Mouse cursors and overlapping sibling NSViews
  • Previous by thread: Re: Good idea/bad idea?
  • Next by thread: Framework for ambient light level?
  • Index(es):
    • Date
    • Thread