gpt4 book ai didi

android - 带或不带括号的 JNIEnv 用法?

转载 作者:太空宇宙 更新时间:2023-11-04 03:42:33 24 4
gpt4 key购买 nike

我很好奇为什么 jni programming guide

The JNI provides a slightly cleaner interface for C++ programmers. The jni.h file contains a set of inline C++ functions so that the native method programmer can simply write:

jclass cls = env->FindClass("java/lang/String");

instead of:

jclass cls = (*env)->FindClass(env, "java/lang/String");

The extra level of indirection on env and the env argument to FindClass are hidden from the programmer. The C++ compiler simply expands out the C++ member function calls to their C counterparts; therefore, the resulting code is exactly the same.

c 和 c++ 指针有什么区别?

最佳答案

C++ 指针是指向类对象 的指针。 C 指针是指向函数 的指针。他们是两个不同的东西。

因为C++对象已经知道环境,所以不需要再传递环境。

C 指针是指向结构的指针,您可以在该结构中调用函数。该函数没有状态,因此您需要传递状态(在本例中,相同的 env 结构,因此它可以找到该结构中的变量。)。

JDKjni.h 中,您会看到 C++ 函数是:

jclass FindClass(const char *name) {
return functions->FindClass(this, name);
}

functions 是指向env 的对象内部的指针。因此 C++ 版本在内部扩展为 C 版本。

关于android - 带或不带括号的 JNIEnv 用法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27353012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com