LuisABOL
LuisABOL

Reputation: 2991

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

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)?

Upvotes: 0

Views: 220

Answers (1)

Jano
Jano

Reputation: 63667

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.

Upvotes: 2

Related Questions