Let's say I have
const uint16_t n = 0x0001;
Then can I cast like this?
const jint j = (jint) n;
Without worrying about endianness of the native platform?
Supplement
I have a function changes a value into an char array.
char * value_to_array(void * value, const size_t size) {
char * array = malloc(size);
if (array != NULL) {
memcpy(array, value, size);
}
return array;
}
Now I should care about the endianness, right? What about the above simple cast?
Yes. JNI primitive types are machine-dependent.
Your second example preserves whatever endian-ness was present in the source, which you haven't specified.