Generate .c source from a .m (Objective-C) file

旧时模样 提交于 2020-01-06 08:48:13

问题


Is it possible to generate a C source file (.c) from an Objective-C source file (.m), using, maybe, GCC or Clang (or another tool)?


回答1:


No, but you may be interested in the C++ rewriter. Given an objective-C file, let's say:

#import <stdio.h>
int main() {
    void (^blk)(void) = ^{
        printf("hi");
    };
    blk();
    return 0;
}

You can get a C++ version with

clang -rewrite-objc main.c

which is great to see how objective-C is implemented. Most of the file will be just C.

Some of the resulting expressions are dense. You'll need patience, C knowledge, and the Objective-C Runtime Reference. http://cdecl.org/ helps with small pieces.



来源:https://stackoverflow.com/questions/11846898/generate-c-source-from-a-m-objective-c-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!