Archive for August 28, 2008

Thursday, August 28, 2008 [Tweets] [Favorites]

Blocks in Objective-C

Apple is adding blocks (a.k.a. closures) to Objective-C (via Ian Baird):

From a technical perspective, blocks fit into C in a couple places: 1) a new declaration type (the caret) which work very much like a magic kind of pointer that can only point to function types. 2) block literals, which capture the computation 3) a new storage class __block 4) a really tiny runtime library.

The new storage class comes into play when you want to get mutable access to variables on the stack. Basically you can mark an otherwise- auto variable with __block…

Update (2008-08-30): Jens Alfke comments.