3 ms·
This post seems to confuse "shouldn’t it be possible to recreate an Objective-C program in straight C" and "can you recreate the ObjC runtime in C". The answer
by gok 8y ago
This post seems to confuse "shouldn’t it be possible to recreate an Objective-C program in straight C" and "can you recreate the ObjC runtime in C". The answer to the second is no, because of the reason mentioned. You can't jump to an arbitrary function with any set of arguments and get the right calling conventions in C. But you can easily call objc_msgSend from C; you just need to cast it to the right function signature first.
The real problem is that there's also no way in C to express the ObjC metadata properly. You could in principle register all the classes/protocols/methods at run time, I suppose, but that would be slow and gross.
- deleted 8y ago[deleted]
- rurban 8y agoIt's certainly not slow and gross, it's in fact how you should implement a proper dynamic language. lua, potion or self e.g. did it this way. Without any assembler or ffi tricks. apply in C is easily doable if your data is tagged.