开发者

JNI interface pointer confusion

开发者 https://www.devze.com 2023-03-26 23:35 出处:网络
I keep seeing the env interface pointer used with and without dereferencing, for example env->DoSomething(arguments)

I keep seeing the env interface pointer used with and without dereferencing, for example

env->DoSomething(arguments)

vs.

(*env)->DoSomething(en开发者_开发问答v, arguments)

Are they actually different things? Is one from an older JNI implementation?


They're the same thing; just a little macro magic. The nicer (first) syntax is enabled in a C++ context.


It's the difference between writing jni code in C and C++, from wikipedia:

Note that C++ JNI code is syntactically slightly cleaner than C JNI code because like Java, C++ uses object method invocation semantics. That means that in C, the env parameter is dereferenced using (*env)-> and env has to be explicitly passed to JNIEnv methods. In C++, the env parameter is dereferenced using env-> and the env parameter is implicitly passed as part of the object method invocation semantics.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号