views:

726

answers:

3

I have no Objective-C experience whatsoever but have a strong C++ background. Is there an automated tool/script or, worst case, some manual method using some excellent reference to port code written in Objective-C to C++? What are the difficulties involved?

Edit: I'm told the code uses Objective-C fairly trivially. It's an iPhone app that probably doesn't use much in the way of OS-level UI. The C++ version is meant for a non-Apple platform where GNUStep is not an option, so Objective-C++ is not an option.

A: 

Objective-C was just a pre-processor (and a runtime library). You'll find more problems in porting all the libraries than the end-user code. Nil-eating behavior is going to be fun when translating.

You are likely to start seeing bad design in all c++ code after using Objective-C frameworks for a while.

Stephan Eggermont
+3  A: 

There are no automated tools that I'm aware of. The dynamic nature of Objective-C is very hard to translate to C++, so quite a bit of brain effort is going to be required for all but trivial Objective-C code. Are you willing to stay on OS X (or keep the GNUStep dependency if you're one of the few people using Objective-C on an OS besides OS X)? If so, the easiest approach is to use Objective-C++ to build a bridge beteen the Objective-C and C++ code. Objective-C++ is an Apple extension to Objective-C and the GCC compiler that allows you to mix Objective-C and C++ code. You can thus create Objective-C objects that call or reference (but not inherit from) C++ objects and you can send Objective-C messages to Objective-C instances from within C++ code.

Barry Wark
+1  A: 

I worked on same problem. And have some solutions - In 2007 I tried support Objective-C in Visual Studio and write my own ObjC runtime, but I do not have more time for writing parser for it. If you have, you can :) http://code.google.com/p/qobjc/ Second solution - I write basic functionality of Foundation Framework written on C++, in this case need port manualy, your code will be on C++ but it will be like on Objective-C. This library worked on iPhone. code.google.com/p/dcocoa/

If you have some ideas or simply want talking about this than write me on e-mail: [email protected]

DoctorSet