需要的建议:Effective Java to C source code converter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15912745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Suggestions needed: Effective Java to C source code converter
提问by Rookie
I googled a bit but could not find any good Java to C source code converter.
我用谷歌搜索了一下,但找不到任何好的 Java 到 C 源代码转换器。
My question is:
我的问题是:
Is this possible ?
Are there any reliable Java to C src converter you can think of which I can have a look at?
这可能吗 ?
是否有任何可靠的 Java 到 C src 转换器,您能想到哪些我可以看看?
回答by Zim-Zam O'Pootertoot
This is possible, but extremely difficult - for starters, you would need to integrate a garbage collector with your C source. There are a few projects that attempt this, e.g. Toba, but they're unreliable and no longer maintained. Usually you'll find somebody attempting something like this in their Master's thesis, after which it is quickly abandoned.
这是可能的,但非常困难 - 对于初学者来说,您需要将垃圾收集器与您的 C 源代码集成。有一些项目尝试这样做,例如Toba,但它们不可靠并且不再维护。通常你会发现有人在他们的硕士论文中尝试这样的事情,之后很快就被放弃了。
If you're doing this to try to speed up your program, then don't - Java is already pretty fast compared to natively compiled code (although it tends to use quite a bit more memory), and your translated C code is not going to be able to take full advantage of the C language.
如果你这样做是为了加速你的程序,那么不要 - 与本地编译的代码相比,Java 已经相当快了(尽管它往往会使用更多的内存),并且你翻译的 C 代码不会运行能够充分利用C语言。
回答by Anderson Green
Universal-transpilercan translate Java programs into several other programming languages, including C. This software is still experimental, but it is already able to translate a subset of Java into C and several other languages.
Universal-transpiler可以将 Java 程序翻译成其他几种编程语言,包括 C。这个软件仍然是实验性的,但它已经能够将 Java 的一个子集翻译成 C 和其他几种语言。
For example, this is one possible input in Java:
例如,这是 Java 中的一种可能输入:
public static int add(int a, int b){
int i = 0;
System.out.println("hello");
return a + b;
}
...and this is the translator's output in C:
...这是翻译器在 C 中的输出:
int add(int a,int b){
int i=0;
printf("%s\n","hello");
return a+b;
}
回答by Amir Saniyan
Use Java2C
: A translator from Java to C language especially for embedded and fast realtime applications, including a javalike runtime System in C.
用途Java2C
:从 Java 到 C 语言的翻译器,特别适用于嵌入式和快速实时应用程序,包括一个类似 java 的 C 语言运行时系统。