Constructing a function call in C
Posted
by 0x6adb015
on Stack Overflow
See other posts from Stack Overflow
or by 0x6adb015
Published on 2010-05-12T11:44:25Z
Indexed on
2010/05/12
11:54 UTC
Read the original article
Hit count: 206
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!
© Stack Overflow or respective owner