How to pass a pointer to a function with variable arguments?

I do not know how to do that!
How to get function pointer in va_list arguments?
Many thanks.

+5
source share
2 answers

Use typedef for the type of function pointer.

+4
source

Typedefs often make it easier to work with function pointers, but are not necessary.

#include <stdarg.h>
void foo(int count, ...) {
    va_list ap;
    int i;
    va_start(ap, count);
    for (i = 0; i < count; i++) {
        void (*bar)() = va_arg(ap, void (*)());
        (*bar)();
    }
    va_end(ap);
}
+3
source