Skip to content

Instantly share code, notes, and snippets.

@kaworu
Created November 26, 2014 19:26
Show Gist options
  • Save kaworu/a00ab9269c06d08f8850 to your computer and use it in GitHub Desktop.
Save kaworu/a00ab9269c06d08f8850 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <Block.h>
typedef void (^vblock)(void);
vblock
f(void)
{
__block int x = 42;
__block int *y = &x;
printf("x=%d, *y=%d, %s\n", x, *y, (y == &x ? "yeah!" : "arg!"));
return Block_copy(^ {
printf("x=%d, *y=%d, %s\n", x, *y, (y == &x ? "yeah!" : "arg!"));
});
}
int
main(int argc, char **argv)
{
vblock b = f();
b();
Block_release(b);
}
@kaworu
Copy link
Author

kaworu commented Nov 26, 2014

%  clang -fblocks blockptr.c -lBlocksRuntime
% ./a.out 
x=42, *y=42, yeah!
x=42, *y=21000256, arg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment