简体   繁体   English

如何将函数指针传递给具有可变参数的函数?

[英]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? 如何在va_list参数中获取函数指针?
thanks so much. 非常感谢。

Typedefs often make working with function pointers easier, but are not necessary. Typedef通常使使用函数指针更容易,但不是必需的。

#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作为函数指针类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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