我可以将本机原始类型转换为 JNI 原始类型而不用担心字节序吗?

Can I cast native primitive type into a JNI primitive type without worrying about endianness?

假设我有

const uint16_t n = 0x0001;

那我可以这样投吗?

const jint j = (jint) n;

不用担心原生平台的字节序?

补充

我有一个函数可以将值更改为 char 数组。

char * value_to_array(void * value, const size_t size) {
  char * array = malloc(size);
  if (array != NULL) {
    memcpy(array, value, size);
  }
  return array;
}

现在我应该关心字节序了,对吧?上面的简单转换呢?

Then can I cast like this?

是的。 JNI primitive types are machine-dependent.

您的第二个示例保留了源中存在的您未指定的任何字节顺序。