F
Francesco Bochicchio
Hi all,
anybody knows if there is a (standard, portable) way to dinamically build
a list of parameters to call a C function? Something like va_start & co,
but to be used on the calling side?
In other words, suppose that I have a generic pointer :
void * f_ptr;
I know that this pointer points to a fuction. I also know the function
parameter types and return types, but only at run time, so I cannot cast
the pointer to something more specific, but have to find a way to call the
pointed function in a generic way, doing something like :
typedef SOME_UNKNOWN_TYPE (*generic_function_pointer)(SOME_OTHER_UNKNOWN_TYPE);
SOME_OTHER_UNKNOWN_TYPE generic_argument_list;
SOME_UNKNOWN_TYPE generic_return_value;
generic_function_pointer generic_f_ptr = (generic_function_pointer)f_ptr;
/* some magic to set generic_argument_list to fake the actual argument
list
*/
generic_return_value = generic_f_ptr( generic_parameter_list );
/*
* some more magic to extract from generic_return_value the actual
* return value
*/
The reason for this is that I would like to be able to do the following:
- load a Linux/Unix dynamic library with dlopen
- given a function name, get the relevant handle (a void *pointer) with dlsym
- by parsing the include files related to the dynamic library, find out
the function parameters and return type (that are therefore known only
at run-time)
- call the fuction using its handle in a 'generic' way, as I tried to
explain above.
I guess I'm asking too much from C, but one never knows
Thanks for any hint you can give me.
Ciao
anybody knows if there is a (standard, portable) way to dinamically build
a list of parameters to call a C function? Something like va_start & co,
but to be used on the calling side?
In other words, suppose that I have a generic pointer :
void * f_ptr;
I know that this pointer points to a fuction. I also know the function
parameter types and return types, but only at run time, so I cannot cast
the pointer to something more specific, but have to find a way to call the
pointed function in a generic way, doing something like :
typedef SOME_UNKNOWN_TYPE (*generic_function_pointer)(SOME_OTHER_UNKNOWN_TYPE);
SOME_OTHER_UNKNOWN_TYPE generic_argument_list;
SOME_UNKNOWN_TYPE generic_return_value;
generic_function_pointer generic_f_ptr = (generic_function_pointer)f_ptr;
/* some magic to set generic_argument_list to fake the actual argument
list
*/
generic_return_value = generic_f_ptr( generic_parameter_list );
/*
* some more magic to extract from generic_return_value the actual
* return value
*/
The reason for this is that I would like to be able to do the following:
- load a Linux/Unix dynamic library with dlopen
- given a function name, get the relevant handle (a void *pointer) with dlsym
- by parsing the include files related to the dynamic library, find out
the function parameters and return type (that are therefore known only
at run-time)
- call the fuction using its handle in a 'generic' way, as I tried to
explain above.
I guess I'm asking too much from C, but one never knows
Thanks for any hint you can give me.
Ciao