Does a Java to C++ converter/tool exist? [closed]

2019-01-10 10:53发布

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?

10条回答
▲ chillily
2楼-- · 2019-01-10 11:13

As said it would be tough to convert Java to C++ but we can have an applicaiton or tool that generates code in Java and equivalnet C++ code.

I know one applicaiton which generates code in C++/Java/C# given a model which has its own way to deifine it.

That tool belongs to CA and name is CA Plex. Search on www.ca.com

查看更多
Root(大扎)
3楼-- · 2019-01-10 11:18

There are programs out there that claim they can do this, but none have gained enough popularity to be frequently mentioned, so we'll leave them at "attempts". Making a converter would require a lot of AI built into your program. The difficulty is increased tenfold when swing is involved because GTK/wxWidgets/Qt/win32 API all differ greatly from swing. But it is possible. Not that the code quality will be great, and no guarantees your program won't crash due to separate memory handling methods, but it's possible.

查看更多
淡お忘
4楼-- · 2019-01-10 11:22

Something neat would be a tool , that translate java to "C++ using Java API" (like GNU GCJ CNI), one problem remain is to manage array.length (array not vector) ...

查看更多
不美不萌又怎样
5楼-- · 2019-01-10 11:26

There is one, bit I am not sure if it actually works. Java to C++ Converter-Tangible Software Soulutions.

It is weird how there are c++ to java converters, but only 1 java to c++ converter.

查看更多
beautiful°
6楼-- · 2019-01-10 11:27

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.

查看更多
够拽才男人
7楼-- · 2019-01-10 11:27

The Firefox HTML5 parser is written in Java and converted to C++. But I think the converter used there is quite specific for this project. Interestingly, it turned out the resulting C++ parser was faster than the old parser written in C++.

I'm also writing a converter as part of the H2 database, under src/tools/org/h2/java. The idea is to allow converting a subset of the H2 database to C++, so this is also not a general purpose translater.

And there is the open source project J2C.

So there are ways to convert Java to C++. But don't expect the translator support all features, and don't expect the resulting code to be any faster than a good Java JVM.

查看更多
登录 后发表回答