JNI接口指针混乱(JNI interface pointer confusion)

编程入门 行业动态 更新时间:2024-10-26 22:19:13
JNI接口指针混乱(JNI interface pointer confusion)

例如,我一直看到使用和不使用解除引用的env接口指针

env->DoSomething(arguments)

(*env)->DoSomething(env, arguments)

他们真的是不同的东西吗? 是一个较旧的JNI实现吗?

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

env->DoSomething(arguments)

vs.

(*env)->DoSomething(env, arguments)

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

最满意答案

这是用维基百科在C和C ++中编写jni代码的区别:

请注意,C ++ JNI代码在语法上比C JNI代码稍微清晰,因为像Java一样,C ++使用对象方法调用语义。 这意味着在C中,使用(* env) - >取消引用env参数,并且必须将env显式传递给JNIEnv方法。 在C ++中,使用env->取消引用env参数,并且env参数作为对象方法调用语义的一部分隐式传递。

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.

更多推荐

本文发布于:2023-08-07 22:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针   混乱   接口   JNI   pointer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!