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?
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.
If you compile without optimizations, and find a suitable C decompiler, you might be able to get partially useful results.
Almost everything in the Objective C language can be represented in C code with calls to the Objective C runtime using "hidden" structure elements.
(Does anyone know if any of the early macro-preprocessor implementations for older versions of the language still exist and are available?)
精彩评论