Filip Petrovic
Filip Petrovic

Reputation: 897

JNI - How to convert 'jint' argument to 'unsigned int' C type value

I have a jni function

native float nativeMethod(int num);

That ties to a C function

void Java_com_package_name_nativeMethod(JNIEnv * env, jobject obj, jint num)
{
    unsigned int nativeUnsignedNum = num;
}

And my C code requires the use of unsigned integers. How can I make this work? Using the code above I get an error: Using 'unsigned int' for signed values of type 'jint'. How can I pass a number ( it will always unsigned/positive ) from Java to a C method, and assign this value to an unsigned integer?

Thanks!

Upvotes: 0

Views: 3296

Answers (1)

Perraco
Perraco

Reputation: 17380

Cast it:

unsigned int nativeUnsignedNum = (unsigned int)num; 

Upvotes: 4

Related Questions