Click to See Complete Forum and Search --> : does the function exist?


Marc from D
April 9th, 2003, 03:03 AM
Hello!

I want to use a Pointer-to-Function to switch between different functions inside our own proprietary operating system.

What I want to archieve is, that without any change my code, my code is able to check whether a function with a known name exists or not.

Do you have any idea how to manage this in plain C?
Thanks!



Example:
I think about something like:

a()
{
//do something
}


main()
{
..
void (*PtF) (void);

if (exist(function a))
{
PtF = a;
PtF();
}
..
}

Gabriel Fleseriu
April 9th, 2003, 03:07 AM
Set up a linked list of structures containing a string and a function pointer. Register every function in the list. To find out whether a function exist, traverse the list and check the names.

Marc from D
April 9th, 2003, 05:16 AM
Thanks, Gabriel!

I think I will have to use this solution, although it has a disadvantage:

Doing this requires, that the application programmer has to think of the list. He has to program things that he does not need in this moment for his project. So the acceptance of my colleagues will not be too good.

I do not think that there is any better solution.

Again: Thanks!

Marc

willchop
April 9th, 2003, 07:43 AM
Maybe not what you want (and not very portable) but if your
developing on a Windows platform and your functions are
contianed in a DLL you can use GetProcAddress() to check
for their existence.

regards, willchop