开发者

Calling C function by generic pointer

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜