zoukankan      html  css  js  c++  java
  • 简单地Block变形C函数调用代码(用作理解)

    struct _block_impl {
        void *isa;
        int Flags;
        int Reserved;
        void *FuncPtr;
    };
    
    struct _main_block_desc_0 {
        unsigned long reserved;
        unsigned long Block_size;
    };
    
    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;
        }
    };
    
    struct _main_block_desc_0 _main_block_desc_0_DATA = {
        0,
        sizeof(struct _main_block_impl_0)
    };
    
    static void _main_block_func_0(struct _main_block_impl_0 *c_self) {
        printf("Block => C 
    ");
    }
    
    
    
    #pragma mark 运行入口
    
    void runBlockFunc() {
        
        struct _main_block_impl_0 impl_0 = _main_block_impl_0((void*)_main_block_func_0,&_main_block_desc_0_DATA,0);
        void (*blk)(void) = (void(*)(void))&impl_0;
        ((void(*)(struct _block_impl *))((struct _block_impl*)blk) -> FuncPtr)((struct _block_impl *)blk);
    }
    
    int main(int argc, char * argv[]) {
        @autoreleasepool {
            runBlockFunc();
            void(^blk)(void) = ^{
                printf("Block => OC 
    ");
            };
            blk();
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
    }

     https://blog.csdn.net/snsn1984/article/details/17716261  关于clang的理解

     通过clang编译oc文件的配置

    clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk main.m


    作者:Billlin
    链接:https://www.jianshu.com/p/f4d0c145fb09
    来源:简书
    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
  • 相关阅读:
    VMware 创建的虚拟机,Xshell无法进行连接
    Centos7 文件修改详情
    Centos7 selinux关闭
    centos7 RPM命令使用
    centos 操作系统优化
    centos 内存使用情况+负载使用情况
    Centos 修改环境变量
    centos7 系统级别(持续更新)
    centos7 常规修改信息(比较杂的)持续更新
    centos7 修改网卡信息
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/11282002.html
Copyright © 2011-2022 走看看