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

£可爱£侵袭症+ 提交于 2019-12-19 07:10:12

问题


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


回答1:


Use a typedef for the function pointer type.




回答2:


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


来源:https://stackoverflow.com/questions/1596476/how-to-pass-a-function-pointer-to-a-function-with-variable-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!