9fans archive / 2001 / 06 / 437 / prev next From: Latchesar Ionkov <lucho@gmx.net> Subject: Re: [9fans] calling function with (variable number of) parameters Date: Wed, 20 Jun 2001 14:23:59 -0400 On Wed, Jun 20, 2001 at 04:30:21PM +0000, Douglas A. Gwyn said: > Latchesar Ionkov wrote: > > I am trying to write a function > > int callf(void *f, int nargs, int *args) > > f is a pointer to a function of a type > > int f(int, int, int, ..., int) > > No, it isn't; at least, not as you have declared callf. > > Also, that is not a proper variadic declaration for the type of f. > I think what you mean is that the actual function definition uses > a *fixed* number of arguments, different for different values of > f, and you're hoping that the passed nargs happens to be > consistent with the function that the passed f points to. You understood what I meant, which was the purpose of the two pseudo declarations. > > callf should copy nargs number of ints from args to the stack and call f, > > and then return f's return value. > > > Is this possible with Plan9 C calling convention? ... > > Do I miss something? Any ideas how to implement it? > > It's an abuse of C under any linkage convention. I know, but that knowledge doesn't help me. > > Unfortunately I don't have any control on the requirements or the way f gets > > its parameters. If there is no way to do it for any number of args, I'll > > limit nargs (and hope nobody will write function with more than 15 > > arguments) and will modify SP with a constant value. > > That will probably be your best bet. > Other solutions would require changes to the interface. The interface is called JNI and I can't change it. Lucho