objective-cgcc

Compile Objective-C Code to C


Is there a way to compile Objective-C code to C? I'd be interested to know how various things are really represented under the hood, but I'm uncomfortable in dealing with Assembly.

For example, I read in a book that methods were represented as functions with unique names based on the class and method name, and that the id type is defined a struct with a single member (isa). Is it possible to view this?


Solution

  • I read somewhere that Objective-C once was implemented as a preprocessor over C, but it's not the case anymore. While the runtime is accessible in C, I don't think there's a way to generate C code from Objective-C code with modern compilers (though it is probably technically feasible without things getting too ugly).

    There are, however, a few relics of that past. If you right click id and select Jump to definition, you'll see the typedef. If you debug your code and look at the structure of an object, you'll see that its first field is always the structure of the superclass, and that it goes all the way up to isa. And Apple provides documentation on the runtime that can give you some insight on how things work.