How to access arrays within an object with JNI?

前端 未结 2 822
暗喜
暗喜 2020-12-13 04:05

JNI tutorials, for instance this one, cover quite well how to access primitive fields within an object, as well as how to access arrays that are provided as explicit functio

2条回答
  •  忘掉有多难
    2020-12-13 05:01

    In gcc 6.3 I get a warning saying "dereferencing type-punned pointer will break strict-aliasing rules" from a line like this:

    jdoubleArray arr = *reinterpret_cast(&mvdata);
    

    But since jdoubleArray is itself a pointer to class _jdoubleArray, there's no need to get the address before casting, and this static_cast works without warnings:

    jdoubleArray arr = static_cast(mvdata);
    

提交回复
热议问题