gpt4 book ai didi

c++ - Java 使用 JNI : why does the JNIEnv pointer get dereferenced twice? 调用 C++

转载 作者:行者123 更新时间:2023-11-28 08:11:37 25 4
gpt4 key购买 nike

此代码直接复制自http://java.sun.com/docs/books/jni/html/objtypes.html#4013

JNIEXPORT jstring JNICALL 
Java_Prompt_getLine(JNIEnv *env, jobject obj, jstring prompt)
{
char buf[128];
const jbyte *str;
str = (*env)->GetStringUTFChars(env, prompt, NULL);
if (str == NULL) {
return NULL; /* OutOfMemoryError already thrown */
}
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, prompt, str);
/* We assume here that the user does not type more than
* 127 characters */
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);
}

为什么都不是

env->GetStringUTFChars(...

也不

(*env).GetStringUTFChars(...

?

最佳答案

来自 earlier在您在问题中链接的文档中:

The first parameter, the JNIEnv interface pointer, points to a location that contains a pointer to a function table

阅读本文似乎 JNIEnv 本身就是一个指针。它甚至是描述段落下方关系的漂亮图片。

关于c++ - Java 使用 JNI : why does the JNIEnv pointer get dereferenced twice? 调用 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8940060/

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