Consider the following C program:
#include
#include
typedef void callptr();
static void fixed(void *something, double val)
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);
}
Your code is not valid. Calling a variadic function requires a prototype indicating that it's variadic, and the function pointer type you're using does not provide this. In order for the call not to invoke undefined behavior, you would have to cast the dynamic_func
pointer like this to make the call:
((void (*)(void *, ...))dynamic_func)(NULL, x);