[newbie] Which cast to go from *jint to *(unsigned long) ?

  • Thread starter Barth?l?my von Haller
  • Start date
B

Barth?l?my von Haller

Hello!

I'm trying to do a c library who will be called from a piece of java
code (JNI). I have the following error when I compile this library :
customJNI.c: In function
`Java_com_xilinx_XHWIF_Boards_custom_customGetSystemInfo':
customJNI.c:55: warning: passing arg 1 of `GetSystemInformation' from
incompatible pointer type

in customJNI.c:55:
result = GetSystemInformation(body, length); // function in custom.c
with jint *body; and jint length;

and in custom.c :
long GetSystemInformation(unsigned long *data, long length) {...}

I understand that GetSystemInformation wait for a pointer unsigned
long and that I give to it an *jint, but I don't know which cast I
must use ?

Thank you, regards

Barthélémy von Haller
 
X

xarax

Barth?l?my von Haller said:
Hello!

I'm trying to do a c library who will be called from a piece of java
code (JNI). I have the following error when I compile this library :
customJNI.c: In function
`Java_com_xilinx_XHWIF_Boards_custom_customGetSystemInfo':
customJNI.c:55: warning: passing arg 1 of `GetSystemInformation' from
incompatible pointer type

in customJNI.c:55:
result = GetSystemInformation(body, length); // function in custom.c
with jint *body; and jint length;

and in custom.c :
long GetSystemInformation(unsigned long *data, long length) {...}

I understand that GetSystemInformation wait for a pointer unsigned
long and that I give to it an *jint, but I don't know which cast I
must use ?

Thank you, regards

Barthélémy von Haller

Just change your function to:

result = GetSystemInformation((unsigned long*) body, (long) length);
 
D

Dan Pop

In said:
Just change your function to:

result = GetSystemInformation((unsigned long*) body, (long) length);

This will shut up the compiler, but it doesn't mean that it is a
particularly brilliant idea, especially if unsigned long and jint
happen to have different sizes.

The OP needs to understand why he is calling GetSystemInformation with
a pointer to jint instead of calling it with a pointer to unsigned long,
as the function expects and change either the caller or the callee so
that they use the same type. The *last* thing you want to do is to
cast a pointer so that the compiler no longer complains about your broken
code.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top