Take the 2-minute tour ×

As I understand correctly, besides the fact that Objective-C language is a strict superset of a "clean" C, added OOP paradigm is simulated by a set of functions partially described in Objective-C Runtime Reference.

Therefore, I'm expecting a possibility to somehow compile Objective-C code in an intermediate C/C++ file (maybe with some asm inserts).

Is it generally possible ?

share|improve this question
Possible? Propably. Practical? Propably not. –  delnan May 5 '11 at 16:08
If we use -rewrite-objc, will rewritten C++ source code uses objective-c runtime library? I mean selectors, messages, objc-msgSend function and others? –  BergP Oct 23 '13 at 9:07

3 Answers 3

up vote 7 down vote accepted

You could use the clang rewriter to convert to C++. Not aware of a way to go to C though.

The rewriter is available via the "-rewrite-objc" command line option.

share|improve this answer
Thanks, C++ could be also an option! Going to check that. –  Martin Babacaev May 5 '11 at 17:31
The rewriter is a start, but if any of your classes inherit from NSObject (and other classes) and use their functionality, converting your source isn't going to do much good. –  bbum May 5 '11 at 17:41
@Catfish_Man: seems that clang's "-rewrite-objc" option is something undocumented. Could you please point me to some resources with explanation (if they exist) ? –  Martin Babacaev May 5 '11 at 17:46
Honestly, it probably won't. At least, it may help at the data layer, depending on how it is architected, and will certainly not help at all with anything UI related. This assumes that your app is cleanly layered (which few ever are :). –  bbum May 5 '11 at 17:55
Yes, the rewritten code still depends on having an objc runtime available –  Catfish_Man Jan 9 at 0:18

As far as I know, there is no software that preprocesses Objective-C code into intermediate C code.

But you could write your Objective-C program entirely in C by calling directly into the Objective-C runtime. The trouble is just that the code might vary between implementations or even different versions of the same runtime.

The question is, is it actually worth the trouble?

share|improve this answer
I already have a project written in Obj-C, and now I have to port some portion of existing code to C/C++ for another platform. –  Martin Babacaev May 5 '11 at 17:20
Have you checked if the other platform has an Objective-C runtime available? For Linux/BSD/etc. there is GNUstep; you could also try Cocotron which has Windows support and offers Obj-C 2.0 features. –  onitake May 6 '11 at 9:55

Theoretically it might be possible to emulate everything in C. But practically, it is not possible. As Objective-C is a superset as you say, there is just so much more in Objective-C that plain old C cannot do, or cannot do easily. Think about all that message dispatching, dynamically selecting / adding methods at runtime... You could at least try with C++, but still, it would be very difficult.

This all sounds like back porting... which is never an enjoyable work. :)

share|improve this answer
All that stuff is already implemented in C, though. Look at the Runtime Reference. –  Josh Caswell May 5 '11 at 17:02

Your Answer


