How to use varargs in conjunction with function pointers in C on Win64?

后端 未结 2 433
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 02:14

Consider the following C program:

#include 
#include 

typedef void callptr();

static void fixed(void *something, double val)         


        
2条回答
  •  甜味超标
    2020-12-18 02:51

    You should work with consistent function definitions, even if that means to use varargs even if not needed. The best is to be as verbose as needed.

    ...

    typedef void myfunc_t(void *, ...);
    

    ...

    myfunc_t dynamic;
    void dynamic(void * something, ...)
    {
    

    ...

    }
    

    ...

    int main()
    {
        double x = 1337.1337;
        myfunc_t *callnow;
        callnow = &dynamic;
        callnow(NULL, x);
    
        printf("%f\n", x);
    }
    

提交回复
热议问题