Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
GNU Compiler for Java
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Comparison of language use=== The authors of CNI claim for various advantages over JNI:<ref>[https://gcc.gnu.org/java/faq.html#2_3 The GCJ FAQ β GNU Project β Free Software Foundation (FSF)<!-- Bot generated title -->]</ref> {{cquote|We use CNI because we think it is a better solution, especially for a Java implementation that is based on the idea that Java is just another programming language that can be implemented using standard compilation techniques. Given that, and the idea that languages implemented using Gcc should be compatible where it makes sense, it follows that the Java calling convention should be as similar as practical to that used for other languages, especially C++, since we can think of Java as a subset of C++. CNI is just a set of helper functions and conventions built on the idea that C++ and Java have the *same* calling convention and object layout; they are binary compatible. (This is a simplification, but close enough.) }} CNI depends on Java classes appearing as C++ classes. For example,<ref>The example comes from: https://gcc.gnu.org/onlinedocs/gcj/Objects-and-Classes.html#Objects-and-Classes {{Webarchive|url=https://web.archive.org/web/20161020222612/https://gcc.gnu.org/onlinedocs/gcj/Objects-and-Classes.html#Objects-and-Classes |date=2016-10-20 }}</ref> given a Java class, <syntaxhighlight lang="java"> public class Int { public int i; public Int(int i) { this.i = i; } public static Int zero = new Int(0); } </syntaxhighlight> one can use the class thus: <syntaxhighlight lang="cpp"> #include <gcj/cni.h> #include <Int> Int *mult(Int *p, int k) { if (k == 0) return Int::zero; // Static member access. return new Int(p->i * k); } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)