views:

330

answers:

3

What data types can be passed between c++ and java/java to c++? Also, are the data types equivalent in terms of size?

+2  A: 

Using Java Native Interface you can pass just about anything between C++ and Java.

jcopenha
and what about from java to c++?
Partial
JNI Supports both directions. It can be tricky and there may be better solutions for you but reading a little about JNI will answer many of your questions and is generally useful knowledge to have.
Duck
JNA seems to be the popular slightly higher-level Java-native interface at the moment.
Tom Hawtin - tackline
+1  A: 

Also check out CNI if using g++. Don't know if JNI is the same way, but you're basically just using C++ to write within a JVM. That is, you can't pass pure C++ objects to Java. Instead, everything must derive from Object.

keraba
What do you mean by "derive from Object"?
Partial
+1  A: 

I prefer Swig myself. It does the JNI wrapping for you allowing calls in any direction you'd like, multithreading, etc. It also works with multiple languages including Java, Python, Perl etc...

Swig is also portable as your C++ code is - I use it myself on Linux and Windows to bridge our C++ code to Java and Python.

Petriborg