View Full Version : array of pointers to functions

19th October 2006, 00:51

I must write a programme in which I have to implement a "handler" which will call the apropriate function from a predefined list of function in C/C++, based on the integer which I have given from the command line.

example: ./program 5 -> will make a system call (a function which is in 5th place in the sys_call_table[])

I was hoping that someone could help me to start, because I don't know how to begin.


19th October 2006, 01:06
Do these functions have the same number and types of parameters?

19th October 2006, 01:16
hmm... This is a set of system function or system calls:
one function is printf, the other is something else so I think that they have different set of parameters...
I have to do the same thing that the operating system uses to make a system call. It calls a function in the array accordingly to a specified address in the array.
printf has some specified address in the array and it automatically calls that addres when needed. My programme has to call that function if I specify the same address in the array but I have to do that explicitly ( I have to perform the call of that function accordingly to the specified position in the array).

19th October 2006, 11:48
Remember that you won't be allowed to do some things which the kernel is allowed to do. In your situation I would use a switch() block to handle each call separately. You'll probably have to map all the arguments to some generic type like void* before entering the switch() and then remap them to proper types when calling the methods. If you were using Qt, I'd tell you to use QMetaObject::invokeMethod(), but I guess you don't use Qt :)