Reputation: 249
I'm working with JNI (developing for Android using Native code).
The case is I would like to send to a Java Class a pointer to a Native object. For that I've seen in casting the pointer direction into a long, like this:
long pointerDirection = (long)pointer;
Is this secure? I've read that in some architectures, a 'long' is just 32 bits, but the pointers just need 32 bits, right? Or in 64 bits they also use 64 bits?
Thanks
Upvotes: 2
Views: 186
Reputation: 545766
Is this secure?
No, definitely not – the standard makes no such guarantee (even though it may work on many machines in practice).
You can cast it safely (only) to the integral type ptrdiff_t
.
Upvotes: 2