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
Gordon Beaton - 22 May 2007 17:54 GMT
> 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
--
Thomas Fritsch - 23 May 2007 12:52 GMT
> 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++.

Signature
Thomas