|
Reflection
I know that this isnt the C forum, but there wasnt one and technically C is a subset of C++ so keep that in mind. Im implementing reflection in my system and I have half of the job done. I currently have the compiler run a program that I buid which parses header files. It takes the function name of each function a creates a c file containing an two parallel arrays, one with function name, the other with the function pointer.
Example output:
char* function_names[] = {"main (int, char**)", "foo (int)", "bar (double)"};
void* function_pointers[] = {&main, &foo, &bar};
This part works perfectly. The hard part is writing the following function:
void run_function(void (*fnptr)(), ...){
}
The function pointer type is obviously not the correct one since it can vary. I know how to pull the arguments off of the stack since i have the prototypes of the functions. What I'm missing is how to actually call the function. Do I have to go to pushing arguments onto the stack with assembly?
Thanks!
Chacham15
|