On Thu, 03 Sep 2009 22:35:35 PDT David Leimbach <
leimy2k@gmail.com> wrote:
>
>
> Actually, reading on a bit more they deal with the "variable capture"
> talking about const copies.
>
> Automatic storage variables not marked with __block are imported as
> const copies.
>
> The simplest example is that of importing a variable of type int.
>
> int x = 10;
> void (^vv)(void) = ^{ printf("x is %d\n", x); }
> x = 11;
> vv();
>
> would be compiled
>
> struct __block_literal_2 {
> void *isa;
> int flags;
> int reserved;
> void (*invoke)(struct __block_literal_2 *);
> struct __block_descriptor_2 *descriptor;
> const int x;
> };
>
> void __block_invoke_2(struct __block_literal_2 *_block) {
> printf("x is %d\n", _block->x);
> }
>
> static struct __block_descriptor_2 {
> unsigned long int reserved;
> unsigned long int Block_size;
> } __block_descriptor_2 = { 0, sizeof(struct __block_literal_2) };
>
> and
>
> struct __block_literal_2 __block_literal_2 = {
> &_NSConcreteStackBlock,
> (1<<29), <uninitialized>,
> __block_invoke_2,
> &__block_descriptor_2,
> x
> };
>
> In summary, scalars, structures, unions, and function pointers are
> generally imported as const copies with no need for helper functions.