Function pointer to void * for RegisterNatives()

75 views
Skip to first unread message

scgames2

unread,
Jan 21, 2020, 10:08:49 AM1/21/20
to android-ndk
RegisterNatives() requires conversion of function pointers to void *'s for assignment to the JNINativeMethod 'fnPtr' field, e.g. via reinterpret_cast as shown here:


(That particular example seems to be ill-formed in that it omits the template arguments - e.g. 'reinterpret_cast(nativeFoo)' - but I'm guessing that's just an error in the documentation.)

My understanding is that the behavior of converting a function pointer to void * in C++ is implementation-dependent, but that in some environments (such as POSIX, with which I believe Android is at least partly compliant) support may be guaranteed. I assume the functionality wouldn't be exposed this way if it wasn't reliable, but being paranoid (and since my code depends on it) I wanted to double-check.

Are there any guarantees in place for this? Is it assumed that Android will always be running on systems where these conversions will work as expected?

Arfa Arfah

unread,
Jan 21, 2020, 1:36:35 PM1/21/20
to andro...@googlegroups.com
RegisterNatives() requires conversion of function pointers to void *'s for assignment to the JNINativeMethod 'fnPtr' field, e.g. via reinterpret_cast as shown here:

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/0f3769b5-c6b7-4f44-b232-f284d2a2c5ba%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages