How does c++ code compile for multiplatform development?

Hello everyone,

I have a more technical low level question for which I can’t find an answer on the web.
How does cocos2d-x c*+ code compile compared to native objective-c or java? What would be the difference in using cocos2d-x and cocos2d-iphone, if say I don’t want multi-platforms and it doesn’t matter the programming language. Does this c*+ compile just like objective-c and java thus having the same performance? Does it run like native code or does it run in a runtime environment like let’s say Adobe’s Air?

I would much prefer a straight answer and not opinions like “which ever language you prefer cause there are minor performance differences”, and please tell me if I was somehow unclear.

Thanks a lot!

I risk violating your request for no opinions but I would think that C++ would actually run slightly faster because it doesn’t have all the memory management and messaging overhead that goes with Objective-C. But, once compiled, it is native code in that it’s been compiled into a native instruction set, the exactly the same as Obj-C is. It’s not like Java which gets compiled into an intermediate instruction set (bytecode).

However, the performance differences, at this level, will really be the least of your concerns. Both languages are performant. It’s the game code that will determine most, if not all, of your performance.

Ok I understoos how it works on iOS, so is it the same for Android? Does cocos2d compile to native instruction sets or bytecode?

Thanks Colin for your prompt and clear response, you answered exactly what I asked!

Native. It’s compiled down to a native instruction set that’s invoked by the bytecode through the JVM.

When you use Cocos2d-x on Android, it’s two parts. It’s a set of Java classes, used to invoke the JNI and to handle any Android API calls (such as to the market, etc). The second part is the native C++ code you’ve compiled down that gets invoked and runs natively.

So… as far as your question goes, everything gets compiled and run as a native instruction set. It’s just how it gets initially invoked, via Obj-C on iOS and via the JVM (or Dalvik) on Android.

Ok, everything is clear to me, thanks a lot!