Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ukma!xanth!nic.MR.NET!srcsip!lhasa!colburn From: colburn@lhasa.SRC.Honeywell.COM (Mark H. Colburn) Newsgroups: comp.lang.c Subject: Re: Functions pointers and stuff Message-ID: <20250@srcsip.UUCP> Date: 10 Apr 89 17:41:18 GMT References: <1715@leah.Albany.Edu> <1989Mar28.050604.8190@utzoo.uucp> Sender: news@src.honeywell.COM Lines: 42 In-reply-to: henry@utzoo.uucp's message of 28 Mar 89 05:06:04 GMT In article <1715@leah.Albany.Edu> rds95@leah.Albany.Edu (Robert Seals) writes: >Is there some sneaky way to execute the function when all I know is >the name of it, i.e., a pointer to several letters which spell it's name. There is a portable way to do this, given that you know the domain of functions which can be called, but it is rather unwieldy. If the function that you are calling is one of the functions in your program, then you can build a jump table that contains the name of all of the functions in your program, along with the function's address. For example, you could do somthing like: void *malloc(); int main(); int foo(); struct func_table { char *func_name; void *(*func_addr)(); } func_table = { { "malloc", malloc }, { "main", main }, { "foo", foo }, }; The disadvantage of doing this is that return values are not handled nicely and all of your functions which go into the table must be declared before the table is built. This works best if all of the functions return the same thing, such as an int, or void, or whatever. Building the table can be kind of a pain as well, however, it could be automated with a few scripts. Providing that all of your return values are handled correctly, or you have different tables for each type of return value, I see no reason why this should not be portable. I don't know if that is what you are looking for, but it might help... Mark H. Colburn MN65-2300 colburn@SRC.Honeywell.COM Systems Administration and Support Honeywell Systems & Research Center