Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I don't know how to accomplish this!
how to get the function pointer in va_list arguments?
thanks so much.

like image 848
drigoSkalWalker Avatar asked Oct 20 '09 18:10

drigoSkalWalker


2 Answers

Typedefs often make working with function pointers easier, 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);
}
like image 70
ephemient Avatar answered Sep 28 '22 07:09

ephemient


Use a typedef for the function pointer type.

like image 30
KeatsPeeks Avatar answered Sep 28 '22 08:09

KeatsPeeks