• 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: curly braces to return value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: curly braces to return value


  • Subject: Re: curly braces to return value
  • From: Howard Moon <email@hidden>
  • Date: Tue, 06 Aug 2013 09:16:19 -0700

> Just ran across this, and I was wondering what y'all thought of it:
>
>  http://cocoa-dom.tumblr.com/post/56517731293/new-thing-i-do-in-code
>
> Of course I knew that you could create a new scope with curly braces, and I sometimes do that just for clarity; for example I might write
>
> {
> CGRect f = thing.frame;
> // do stuff to f
> thing.frame = f;
> }
>
> That's mostly just to clarify that these lines go together, making up for the fact that you can't modify a view's frame by assigning directly into its struct members.  The local scope is a bonus. However, I never knew that you could return a value from a curly-braces scope and treat it as an rvalue:
>
> thing.frame = {
> CGRect f = thing.frame;
> // do stuff to f
> f;
> }
>
> It's like, did C suddenly turn into Ruby? :) Anyway, I'd be interested in hearing opinions of this. I'm a bit leery of taking advantage of GCC extensions to the C language, not least because you never know when they will vanish out from under you; I still haven't recovered from the day that local function-within-method went away and left me twisting in the wind... :))) m.
>
> --

Doesn't that GCC extension require ({…}), not just {…}?

(And since it's a GCC extension, it's not portable.)

-Howard


 _______________________________________________
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: curly braces to return value
      • From: Wim Lewis <email@hidden>
References: 
 >curly braces to return value (From: Matt Neuburg <email@hidden>)

  • Prev by Date: curly braces to return value
  • Next by Date: Re: curly braces to return value
  • Previous by thread: curly braces to return value
  • Next by thread: Re: curly braces to return value
  • Index(es):
    • Date
    • Thread