Does a Java to C++ converter/tool exist?

n00ki3 picture n00ki3 · Feb 17, 2009 · Viewed 96.1k times · Source

I always asked myself if it would be possible to make a Java to C++ converter.

Maybe a tool that converts the Java syntax to the C++ syntax?

I am aware that the languages differ, but simple things like loops where the semantics match 1 to 1.

Is there such a tool? Or is it possible to make one?

Answer

cletus picture cletus · Feb 17, 2009

It's possible to do anything given enough time, money and resources. Is it practical? Beyond trivial examples not really. Or rather it depends on what constitutes an acceptable error rate.

The real problem is that the idioms are different in Java to C++. Java to C# for example would actually be far easier (because the idioms are much more similar). The biggest of course is that C++ has destructors and manually managed memory. Java uses finally blocks for this kind of behaviour and has garbage collection.

Also Java has a common Object supertype. C++ doesn't.

The generics to templates would be nigh on impossible I would imagine.