是否有 Java 到 C++ 转换器/工具存在吗?

发布于 2024-07-13 08:57:24 字数 1542 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

記憶穿過時間隧道 2024-07-20 08:57:27

有一个,我不确定它是否真的有效。
Java 到 C++ 转换器 - 有形软件解决方案

奇怪的是,有 c++ 到 java 的转换器,但只有 1 个 java 到 c++ 的转换器。

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.

〆一缕阳光ご 2024-07-20 08:57:27

如前所述,将 Java 转换为 C++ 很困难,但我们可以拥有一个应用程序或工具来生成 Java 代码和等效的 C++ 代码。

我知道一个应用程序可以在给定模型的情况下生成 C++/Java/C# 代码,该模型有自己的定义方式。

该工具属于 CA,名称为 CA Plex。
在 www.ca.com 上搜索

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

吾家有女初长成 2024-07-20 08:57:27

有一些程序声称它们可以做到这一点,但没有一个程序获得足够的知名度而经常被提及,因此我们将它们留在“尝试”中。 制作转换器需要在程序中内置大量人工智能。 当涉及到swing时,难度就增加了十倍,因为GTK/wxWidgets/Qt/win32 API都与swing有很大不同。 但这是可能的。 并不是说代码质量会很好,也不能保证您的程序不会由于单独的内存处理方法而崩溃,但这是可能的。

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.

女皇必胜 2024-07-20 08:57:27

主要问题是 java 是一种为与虚拟机对话而编写和设计的语言。 我想这是可能的,但你所剩下的只是一个优化得很差的应用程序,其中一个自翻译层正在做虚拟机已经做的事情。 我的意思是,当然,这是可能的,但它仍然不是我能想到的任何解决方案。 如果您希望将缓慢的 Java 应用程序变成原生应用程序,也许您想得太难了,只需使用像 JET 这样的应用程序,它实际上非常好,并且会给您原生应用程序带来的好处。 当然,如果虚拟机已经在做应用程序要求它做的事情,就像本机代码可以做的那样(它会发生..有时:P),它可能不会改变任何事情。

Java 到 c#,听起来更合理,因为这两种语言都以类似的方式编写,与框架本身进行对话,但这仍然会使代码非常未优化,因为无法超越从头开始为特定框架编写的代码。

The main issue is that java is a language that is written and designed to talk to a VM. I suppose it would be possible, but all you would be left is a very poorly optimized application with a self translating layer doing what the VM already does. I mean, sure, it is possible, it still wouldn't be a solution for anything i could think of. If your looking to make your sluggish java app native, maybe your thinking too hard, just use an application like JET, its actually quite good, and will give you the benefits a native app would bring. Of course if the VM is already doing what the app is asking it to do just as well as native code could(it happens.. sometimes :P) it might change nothing.

Java to c#, tho, sounds more reasonable, as both the languages are written in similar ways, talking to a framework as such, but this would still leave code very much unoptimized as code written from scratch for a particular framework can not be bested.

走野 2024-07-20 08:57:27

取决于

​代码将被使用的领域,从学习的角度来看也许它可能很有趣。

我刚刚通过谷歌找到了这个,因为我记得在大学里看到过一个基于 uml 创建代码的。

http://www.tangiblesoftwaresolutions.com/Order/Order_Upgrade_Instant_CPlus_Java_Edition.htm

Depends on the domain of where the code will be used, from a learning perspective perhaps it might be interesting.

i just found this via a google as I remembered seeing one in Univeristy that created code based on uml.

安稳善良 2024-07-20 08:57:27

Java 到 C 实际上是最简单的。 请记住,您需要转换语言,如果您这样做,新编译器可以转换所需的库。 换句话说,Swing 和 AWT 应该不是一个大问题...

我首先要仔细研究一下 Java 本机接口 (JNI)。 JNI 是 java 的一部分,允许它与 C 和 C++ 一起使用。 我从这里开始的原因是,Java 的某些部分如何用 C 实现是相当明显的。一旦我掌握了基本结构,例如 Java 对象如何映射到 C 结构(struct)以及几乎所有内容如何在 C 中实现, Java 是一个包含数组的对象,我可能会查看 Open JDK 源代码。

实际的转换器必须转换所有导入的 Java 库(及其导入的库等等...),这意味着您将需要所有内容的源代码。 由于 Java 库很大,因此这种转换不是一个小任务。

这个过程会很耗时,但不需要人工智能。 但是,我认为没有理由执行这样的转换。 它失去了Java的可移植性,并且不会获得C的效率(除了它会编译为本机代码,但最好直接从Java编译机器代码)。

Java to C would actually be the easiest. Remember you need to convert the language, If you do that, the required libraries can be converted by your new compiler. In other words Swing and AWT should not be a big problem...

I would start by taking a good look at the Java Native Interface (JNI). The JNI is a part of java which allows it to be used with C and C++. The reason I would start here is that it becomes fairly obvious how parts of Java may be implemented in C. Once I had a grasp on basic structures, like how Java Objects can be mapped onto C structures (struct) and how pretty much everything in Java is an Object including arrays, I might peek at the Open JDK source code.

The actual converter would have to convert all the imported Java libraries (and their imported libraries and so on...) which means you would need the source code for everything. This conversion no small task since the Java libraries are large.

The process would be time consuming, but no AI should be required. However, I see no reason to perform a conversion like this. It looses the portability of Java and would not gain the efficiency of C (except that it would be compiled to native code, but it would be better to compile the machine code directly from the Java).

会傲 2024-07-20 08:57:27

一些巧妙的工具将java转换为“使用Java API的C++”(如GNU GCJ CNI),剩下的一个问题是管理array.length(数组而不是向量)...

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) ...

梨涡 2024-07-20 08:57:26

只要有足够的时间、金钱和资源,任何事情都是可能的。 实用吗? 除了琐碎的例子之外,事实并非如此。 或者更确切地说,这取决于可接受的错误率是多少。

真正的问题是 Java 和 C++ 中的习惯用法不同。 例如,从 Java 到 C# 实际上会容易得多(因为习惯用法更加相似)。 最重要的当然是 C++ 有析构函数和手动管理内存。 Java 使用finally 块来实现这种行为,并且具有垃圾收集功能。

Java 还有一个通用的 Object 超类型。 C++ 没有。

我认为模板的泛型几乎是不可能的。

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.

原来是傀儡 2024-07-20 08:57:26

Firefox HTML5 解析器是用 Java 编写并转换为 C++。 但我认为那里使用的转换器对于这个项目来说是非常具体的。 有趣的是,结果证明生成的 C++ 解析器比用 C++ 编写的旧解析器更快。

我还在 src/tools/org/h2/java 下编写了一个转换器作为 H2 数据库 的一部分。 这个想法是允许将 H2 数据库的子集转换为 C++,因此这也不是通用翻译器。

还有开源项目 J2C

所以有一些方法可以将Java转换为C++。 但不要指望翻译器支持所有功能,也不要指望生成的代码比良好的 Java JVM 更快。

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.

云淡月浅 2024-07-20 08:57:26

毫无疑问,这是可能的,但事情不会那么简单。 它将是一个生成 C++ 的 Java 编译器。

如果你想从头开始,这将非常困难,你必须完成 javac 和 JVM 为你做的所有工作(例如垃圾收集)。

顺便提一句。 Google 有一个 Java 到 JavaScript 编译器(包含在 GWT 中)

Is is possible, no question, but it won't be so simple. It would be a Java compiler which generates C++.

If you want to do that from scratch, it will be very hard, you have to do all the work javac and the JVM do for you (e.g. garbage collection).

Btw. Google has a Java to JavaScript compiler (included in GWT)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文