开发者

Va_list to access second argument

I try to write a function such that :

int solve(double* x, double xA, double xB, double zeps,
          double funct(double x, double*), ...)

Here, 'funct' is another function passed as an argument. Now I would like to use va_list to access the second argument of this function 'funct' which is a double*. So I do:

va_list poin开发者_运维技巧t_arg ;
va_start ( point_arg , funct ) ;
double  pp = va_arg ( point_arg , double  );
double * pp = va_arg ( point_arg , double * );

It seems, as far as I understand that the first va_arg I use succeeds to find the first argument of the function 'funct' which is a double. However, the second use of va_arg fails to get the proper pointer to the double (the second argument). Do you know if this is possible and if not how to do it ?


You've misunderstood the way that function pointers work. A function pointer is a pointer to the location in memory when the function is stored, and it doesn't contain any information about the parameters to that function. You must supply the parameters to the function yourself when you invoke the function pointer.

So you cannot access the parameters to the funct pointer because those parameters don't exist yet. They will only exist once the pointed-do function is invoked, which would presumably happen inside your code.


funct does not use ellipsis you can't apply va_list function on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜