Reputation: 367
Is there any method to call a function, by just knowing its address in a pointer, lets say a pointer of type "void *(*)(void *)"
, and number and type of its parameter?
The function could have any number of parameters!
Upvotes: 3
Views: 223
Reputation: 283674
No, not in any portable or standard way.
However, there is a standard way to pass a variable number of arguments between functions. Have a look at vsprintf
. Basically, you need a version of the function that accepts a va_list
.
Upvotes: 5
Reputation: 753900
Roughly, no.
You have to know the number of parameters before you can write the call, and therefore the types too. Therefore, you cannot write one line of code that accurately calls a function that takes 0 parameters or 1 parameter or 2 parameters. You could always provide 2 and trust things will work - but the compiler will (justifiably) give warnings.
Upvotes: 2