JNIEnv *

D

DGG

I am reading the JNI spec. One feature puzzles me. There is this
universial JNIEnv *env pointer in every function. However, if it is C,
you use (*env)->xxxx to access the fields in the environment; if it is
in C++, you use env->xxxx to access it.

Does anybody know what's the rationale behind such a design?

Thanks
 
G

Gordon Beaton

I am reading the JNI spec. One feature puzzles me. There is this
universial JNIEnv *env pointer in every function. However, if it is
C, you use (*env)->xxxx to access the fields in the environment; if
it is in C++, you use env->xxxx to access it.

Does anybody know what's the rationale behind such a design?

In both cases, you are invoking member functions on the JNIEnv object.
In C, you need to explicitly pass the "this" reference to each method.
In C++ the result is exactly the same code, but the compiler removes
the extra level of indirection and inlines the first argument for you.

/gordon

--
 
T

Thomas Fritsch

DGG said:
I am reading the JNI spec. One feature puzzles me. There is this
universial JNIEnv *env pointer in every function. However, if it is C,
you use (*env)->xxxx to access the fields in the environment; if it is
in C++, you use env->xxxx to access it.

Does anybody know what's the rationale behind such a design?
As far as I understand the JNI spec (see
<http://java.sun.com/docs/books/jni/html/other.html#30951> ),
the rationale behind that is to make it simpler for the programmer.
But unfortunately they can offer this simplification only for C++
language, but not for C language.

BTW: Because of the above I prefer to do JNI-programming in C++.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top