Given that I have a pointer to a function (provided by dlsym()
for example) and a linked list of typed arguments, how can I construct a C function call with those arguments?
Example:
struct param {
enum type { INT32, INT64, STRING, BOOL } type;
union { int i32; long long i64; char *str; bool b; } value;
struct param *next;
};
int call_this(int (*function)(), struct param *args)
{
int result;
/* magic here that calls function(), which has a prototype of
f(int, long long, char *, bool); , when args consist of a linked list of
INT32, INT64, STRING, BOOL types. */
return result;
}
The OS is Linux. I would like the solution to be portable across MIPS, PPC and x86 (all 32 bits) architecture, using GCC as the compiler.
Thanks!