Under the Bridge

Returning Bracketed Expressions

Now this is a GCC feature extension also present in Clang of which we had not previously been aware:

Ever since I found out that a GCC C extension causes a code block to return a value if you enclose it in round brackets, I’ve been using it in my code. What do you think?

self.bounds = ({
CGRect bounds = self.bounds;
bounds.size.height = self.currentYPosition + SHEETINSETY;

Cool beans. Improves succinctness and reduces declaration scopes, both of which are bug-avoiding Good Things™. Plus there’s the extra bonus of confusing your coworkers by checking in code using extensions they’re probably not aware of either, which is always good for a chuckle. Or “cackling with unholy glee”, as other people see it. Whichever.

h/t: @steipete!


Hey, you can use this to call blocks inline at their definition too!