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 param开发者_C百科eters!
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
.
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.
精彩评论