简体   繁体   English

为什么通过JNI在Java和C ++之间传递不正确的值?

[英]Why are incorrect values being passed between Java and C++ via JNI?

I want to pass a double value from C++ to Java (Android) using JNI. 我想使用JNI将C ++中的double值传递给Java(Android)。

Relevant C++ code: 相关的C ++代码:

JNIEXPORT jdouble JNICALL
Java_test_MPEG_DASH_ffmpeg_PlayerUI_Notif(JNIEnv* env, jobject obj,jint st){

    jdouble p=receiver->buffer->Notify();
    LOGI("Notifyyyyyyyyy from jni is %d ",p);
    return p;
}

Displays 35, 36, etc 显示35,36等

When accessed in Java by calling the native method, the wrong values are returned: 0.0000133333 通过调用本机方法在Java中访问时,将返回错误的值:0.0000133333

Relevant Java code: 相关的Java代码:

double buf=Notify();
Log.d(TAG, "Bufffffffffffffffffffffffffer :"+buf" ms");

Why are the values inconsistent? 为什么值不一致?

"%d" is not a format specifier compatible with floating point types. “%d”不是与浮点类型兼容的格式说明符。 If you use it, you will force a misinterpretation of the bits comprising the jdouble, and print an incorrect value. 如果使用它,将强制误解构成jdouble的位,并打印不正确的值。

It's likely that the value returned to Java is correct (there's a fair amount of type enforcement there), and that being logged incorrect. 返回Java的值可能是正确的(那里有相当多的类型强制执行),并且记录不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM