Passing an int by reference
I have a C function prototyped as:
int func(int *Num)
Num is used to pass data but is modified in the function.
I want to call func() from Java and get the new value of Num back. Since primitives are passed by value, how do I specify the Java prototype?
I.e.
public native int func(<WHAT GOES HERE?>)
Many thanks.
[370 byte] By [
achalk] at [2007-9-26 6:33:37]

>want to call func() from Java
You can't.
The signature that you have provided is not a valid java native method signature. So you will have to create a native method and call that one.
In C that would be like
int i = <get java>
func(&i)
<set java> = i
The 'get' and 'set' can be implemented in a number of ways: member functions, member variables (static or not), method argment.
> >want to call func() from Java
>
> You can't.
>
> The signature that you have provided is not a valid
> java native method signature. So you will have to
> create a native method and call that one.
>
> In C that would be like
>
> int i = <get java>
> func(&i)
> <set java> = i
>
> The 'get' and 'set' can be implemented in a number of
> ways: member functions, member variables (static or
> not), method argment.
You mean that when modifying Java primitives in C you have to have two methods -- one to set and one to get the value?
Regards.
>You mean that when modifying Java primitives in C you have to have two methods.
Nope.
But we aren't discussing primitives. We are discussin JNI. And to use a primitive value in JNI, as discussed, you have to get it 'into' the function and then get the value 'out of' the function. That requires two 'methods' (which could be implemented as two java methods, but does not have to be.)