简体   繁体   中英

Is it possible to call a function using a function pointer with number and type of arguments known only at runtime

Background : I am creating a library to allow a process to call another function from another process using IPC.

Each process needs to register its functions with:

void register_function(char* function_name, 
                       void(*func)(), 
                       int nb_parameters, 
                       const int parameters_type[])

My problem is when I need to actually call the function after it was requested through the IPC, I cannot call the function because the number and types of parameters is known only at runtime.

I am thinking about calling the function using a struct created dynamically but I'm not sure about the order of arguments I should use or even if it is a good idea.

Any idea ?

I would suggest you use two arguments:

1st argument type: (int). Meaning -> number of arguments

2nd argument type: (void*) -> list with so many arguments as indicated by the 1st argument.

Just like argc and argv in main.

Best regards.

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