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?

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!

UPDATE:

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

Alex | July 27, 2013

Leave a Reply