Function pointer with variable number of arguments

I have a function with the following prototype:

void func(int an, ...);

And I would like to save the address of this function and call it later. I really don't know how to do this, I desesperatly tried:

void (*funcPtr)(int, ...);  // Declaration
funcPtr = func;     // Storage
(*funcPtr)(3,2,5);      // Call

This code compiles fine, but when executed it crap, when I enter my function, the arguments in mine are va_listnot the ones I sent.

Thanks in advance

EDIT: Well, I just forgot the first argument. In my code above, the call string should be replaced with:

(*funcPtr)(3,3,2,5);        // Call
+4
source share
1 answer

Functions are pointers in a natural way. So you can just call:

funcPtr(3,3,2,5);

, . , , "" .

+1

Source: https://habr.com/ru/post/1538324/


All Articles