Is it possible to create/generate a pointer declaration similar to:
void (*foo)(int, float);
bool (*foo)();
char (*foo)(char, int);
But without knowing the type of the arguments or the return type until run-time.
The function declaration would be read from a string which would specify the return and argument type (if any) then (if possible) stored in a c++ container.
Can it be done at run-time (not compile-time) ? And also C++11 can be used if necessary.
I really doubt this can be done in a statically typed language like C++ but if it can be done then what approach would someone use. No need for code (but it's appreciated) just some guidance to what must be used.
EDIT:
After testing several ideas it turns out that it can't be achieved (directly) with C++. Luckily I found the dyncall library which allows me do do it (indirectly) and on a quite large number of platforms.
Example function:
double sqrt(double x);
Using dyncall to call the function:
double r;
DCCallVM* vm = dcNewCallVM(4096);
dcMode(vm, DC_CALL_C_DEFAULT);
dcReset(vm);
dcArgDouble(vm, 4.2373);
r = dcCallDouble(vm, (DCpointer)&sqrt);
dcFree(vm);
Strings can also be used to declare the structure of a function.
C function prototype dyncall signature
void f1(); ")v"
int f2(int, int); "ii)i"
long long f3(void*); "p)L"
void f3(int**); "p)v"
double f4(int, bool, char, double, const char*); "iBcdZ)d"