简体   繁体   中英

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 parameters!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM