Block是带有“自动变量值的匿名函数”。
Block省略了返回值和参数列表。
Block 实质栈上Block的结构体实例
Block源代码如下:
struct __block_impl {
void *usa;
int Flags;
int Reserved;
void *FuncPtr;
}
struct __main)block_impl_0 {
struct __block_impl impl;
stryct __main_block_desc_0* Desc;
__main_block_impl_0(void *fp, struct __main_block_desc_0 *desc, int flags=0){
impl.isa = &_NSConcreteStackBlock;
impl.Flags = flags;
impl.FuncPtr = fp;
Desc = desc;
}
static void __main_block_func_0(struct __main_block_impl_0 *cself)
{
printf("Block\n");
}
static struct __main_block_desc_0{
unsigned long reserved;
unsigned long Block_size;
} __main_block_desc_0_DATA = {
0,
sizeof(struct __main_block_impl_0)
};
int main()
{
void (*blk)(void) =
(void (*)(void)) &__main_block_impl_0(
(void *)__main_block_func_0, &__main_block_desc_0_DATA);
((vodi (*) (struct __block_impl *))
(struct _block_impl *)blk)->FuncPtr)((struct __block_impl *) blk);
return 0 ;
}