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

前端 未结 2 1451
滥情空心
滥情空心 2021-01-12 23:21

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

相关标签:
2条回答
  • 2021-01-12 23:57

    Use a typedef for the function pointer type.

    0 讨论(0)
  • 2021-01-13 00:05

    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);
    }
    
    0 讨论(0)
提交回复
热议问题