Sign in to follow this  

Automatic Java to C/C++

This topic is 2492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Java has been a mature language for decade+ now. Is there a recommended tool/util that converts java code to c/c++?

My situation is:

I develop in java but have create and later maintain a c++ port. The application is embedded, so JNI or similar native access technologies won't do.

I just need a basic language to language converter. Because being game/computation, my java code uses very little standard java libraries. Lots of writing to int/float buffers and some string use for file loading/debuggin purposes.

To get the port started, I imagine using an automatic tool that converts my java code to c/c++. However good/bad the quality of the auto-port, I would manually fix/tweak anyways until the code base works.

Since the java version is actively developed, I cannot port once to c/c++ and be done with. I would do a complete port from java to c++ every major version. I think this is perhaps easier than manually applying java code base changes to the c/c++ port?

I do have the option to develop in c/c++ and port to java. But I imagine a c/c++ to java code converter is far harder than the reverse direction. So that's why I develop in java for now.

Thanks


Share this post


Link to post
Share on other sites
Converters do exist, but they are intended (and priced) for enterprise use, and their output is not generally suitable for use without extensive manual cleanup, which might exceed the time to do the conversion by hand. C++'s lack of automatic memory management, and its idiomatic use of value types, cause serious problems for automatic conversion.

Are you sure that Java won't work for your embedded application? Java was originally [i]designed[/i] for embedded devices, after all, so a JRE may well exist for your platform. For that matter, you could just compile the Java to native code with GCJ.

Share this post


Link to post
Share on other sites
Which platforms specifically?

Does the application use any native functionality, such as AWT/Swing/SWT, NIO networking or NIO-related classes, Image-related APIs, OpenGL?

Share this post


Link to post
Share on other sites
How ugly is the process? Are there few recommended ones I can try out?

I imagine any converter can convert:
float[] javaArray = new float[100];
to
float* cppArray = new float[100];

Since for me memory allocations mostly happen once at program start, it's not too bad for me to manually insert delete[] cppArray uppon object destruction/program termination.

So I imagine for these programs that rely little on java.whatever libraries, a converter would give relatively good result.

[quote name='Sneftel' timestamp='1297875048' post='4775014']
Converters do exist, but they are intended (and priced) for enterprise use, and their output is not generally suitable for use without extensive manual cleanup, which might exceed the time to do the conversion by hand. C++'s lack of automatic memory management, and its idiomatic use of value types, cause serious problems for automatic conversion.

Are you sure that Java won't work for your embedded application? Java was originally [i]designed[/i] for embedded devices, after all, so a JRE may well exist for your platform. For that matter, you could just compile the Java to native code with GCJ.
[/quote]


Apple's mobile platforms, Qualcomm BREW are just two that don't support java, at least out of the box.

Only AWT/Swing/SWT I use is java.awt.image. But I can use a standard c/c++ .png library and compile into my code.

For IO, all I use is java.net.URL and java.io.FileInputStream to read file/image and parse myself. Is there a cross-platform c/c++ library that handles net i/o so I don't have to use the differing iOS or BREW net file reading APIs?

No OpenGL.

[quote name='Antheus' timestamp='1297877968' post='4775030']
Which platforms specifically?

Does the application use any native functionality, such as AWT/Swing/SWT, NIO networking or NIO-related classes, Image-related APIs, OpenGL?
[/quote]

Share this post


Link to post
Share on other sites

This topic is 2492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this