I'm building a stack-based virtual machine for fun. I'm trying to implement an instruction to call C library functions. I have the name of the function as a C-string, the arguments to be passed, and the number of arguments. I'd also like to call variadic functions such as printf. If this cannot be done in standard C, platform specific solution is also welcome, either for Windows or for POSIX systems.
I looked at dlsym
and GetProcAddress
, but still the problem is that the argument list should be known at compile time, just as a normal C function. I need a way to dynamically construct the argument list and call the function with it.