Block2

作者: 写代码写到人生巅峰 | 来源:发表于2017-05-15 11:36 被阅读0次

1.clang -rewrite-objc 源代码文件名 -> C++源代码

void (^blk)() = ^ {
    printf("Hello world");
};
 
void (^blk2)(int b) = ^(int b) {
    printf("%d", b);
};

C++源代码

 Block本质:指向函数的指针,实质 Objective-C对象
 
 ****************************  main  ***************************
 
 int main(int argc, const char * argv[]) {
 
     void (*blk)() = ((void (*)())&__main_block_impl_0((void *)__main_block_func_0, &__main_block_desc_0_DATA));
     
     void (*blk2)(int b) = ((void (*)(int))&__main_block_impl_1((void *)__main_block_func_1, &__main_block_desc_1_DATA));
 
     return 0;
 }
 
 static void __main_block_func_0(struct __main_block_impl_0 *__cself) {
 
    printf("Hello world");
 }
 
 static void __main_block_func_1(struct __main_block_impl_1 *__cself, int b) {
 
    printf("%d", b);
 }

****************************  blk  ***************************
 
struct __main_block_impl_0 {
    struct __block_impl impl;
    struct __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 struct __main_block_desc_0 {
     size_t reserved;
     size_t Block_size;
 } __main_block_desc_0_DATA = { 0, sizeof(struct __main_block_impl_0)};
 
 
 ****************************  blk2  ***************************
 
 struct __main_block_impl_1 {
     struct __block_impl impl;
     struct __main_block_desc_1* Desc;
 
     __main_block_impl_1(void *fp, struct __main_block_desc_1 *desc, int flags=0) {
         impl.isa = &_NSConcreteStackBlock;
         impl.Flags = flags;
         impl.FuncPtr = fp;
         Desc = desc;
     }
 };
 
 static struct __main_block_desc_1 {
     size_t reserved;
     size_t Block_size;
 } __main_block_desc_1_DATA = { 0, sizeof(struct __main_block_impl_1)};
 
 
  **************************  __block_impl  *****************************
 
 struct __block_impl {
     //  block为OC对象: _NSConcreteStackBlock、_NSConcreteGlobalBlock、_NSConcreteMallocBlock
     void *isa;
     int Flags;
     int Reserved;
     void *FuncPtr;
 };

自动变量会追加到结构体__main_block_impl_0 中

相关文章

  • block传值理解

    就是在一个类里把block1当参数传过另一个block2,首先先调用block2的实现方法,然后在block2里调...

  • Block2

    1.clang -rewrite-objc 源代码文件名 -> C++源代码 C++源代码 自动变量会追加到结构体...

  • 2019-11-28 锚点定位+滚动

    html: ..... ..... ..... ..... 滚动到block1 滚动到block2 滚动到bloc...

  • 2019-06-29 Keras/kernel visual

    Model block1 (64 of 64): 方向边缘和颜色 block2 (first 64 of 128)...

  • 工欲善其事,必先利其器系列之 UIButton+Category

    UIButton 按钮点击常用效果,本文介绍: 1、BtnClickBlock 点击Block2、使用颜色设置按钮...

  • iOS常见的面试题

    1、block2、多线程3、copy&mutablecopy4、锁5、app优化6、runtime7、kvo8、k...

  • Block

    1、Block2、捕获变量3、__block4、Block内存管理5、Block的循环引用 将函数及其执行上下文(...

  • hdfs读写文件过程

    以写入100M文件为例: Client将FileA按64M分块。分成两块,block1和Block2; Clien...

  • 越严厉越是对你好

    今天用了一天的时间完成了预计三天完成的工作,在吃完晚饭后,让师哥帮忙检查做好的高型的block2的floorpla...

  • 人生就是不断尝试的过程

    今天开始做block2,第一步就是做floorplan,我给自己定了六天的时间做好这一步,虽然很懵,但我会不断尝试...

网友评论

      本文标题:Block2

      本文链接:https://www.haomeiwen.com/subject/cuxhxxtx.html