简体   繁体   中英

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.

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);
}

使用typedef作为函数指针类型。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM