• 带__Block和不带的差别


    带了__block

    #pragma clang assume_nonnull end
    
    struct __Block_byref_i_0 {
      void *__isa;
    __Block_byref_i_0 *__forwarding;
     int __flags;
     int __size;
     int i;
    };
    
    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 int __main_block_func_0(struct __main_block_impl_0 *__cself, int index) {
    
            index += 1;
            printf("====> %d
    ",index);
            return index;
        }
    
    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)};
    int main () {
        __Block_byref_i_0 i = {(void*)0,(__Block_byref_i_0 *)&i, 0, sizeof(__Block_byref_i_0), 10};
        int (*testBlk)(int) = ((int (*)(int))&__main_block_impl_0((void *)__main_block_func_0, &__main_block_desc_0_DATA));
        printf("---> %d
    ",((int (*)(__block_impl *, int))((__block_impl *)testBlk)->FuncPtr)((__block_impl *)testBlk, (i.__forwarding->i)));
        return 0;
    }
    #import <Foundation/Foundation.h>
    
    int main () {
        int __block i = 10;
        int (^testBlk)(int) = ^int(int index){
            index += 1;
            printf("====> %d
    ",index);
            return index;
        };
        printf("---> %d
    ",testBlk(i));
        return 0;
    }

    没有带__block

    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 int __main_block_func_0(struct __main_block_impl_0 *__cself, int index) {
    
            int addIndex = index + 1;
            printf("====> %d
    ",addIndex);
            return addIndex;
        }
    
    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)};
    int main () {
        int i = 10;
        int (*testBlk)(int) = ((int (*)(int))&__main_block_impl_0((void *)__main_block_func_0, &__main_block_desc_0_DATA));
        printf("---> %d
    ",((int (*)(__block_impl *, int))((__block_impl *)testBlk)->FuncPtr)((__block_impl *)testBlk, i));
        return 0;
    }
    #import <Foundation/Foundation.h>
    
    int main () {
        int i = 10;
        int (^testBlk)(int) = ^int(int index){
            int addIndex = index + 1;
            printf("====> %d
    ",addIndex);
            return addIndex;
        };
        printf("---> %d
    ",testBlk(i));
        return 0;
    }
  • 相关阅读:
    SpringData JPA接口总结
    使用allatori混淆代码
    Oracle查看表空间大小
    Mac常用命令
    Web.config或App.config下section
    ansi、unicode、UCS、UTF等概念(转)
    强名称程序集与GAC
    指针和引用的区别(转)
    .NET程序员应该知道些什么(转)
    dispose,null和close的区别
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/11282221.html
Copyright © 2020-2023  润新知