Functions pointers and stuff

Oliver Laumann net at tub.UUCP
Tue Mar 28 20:03:08 AEST 1989


In article <1715 at leah.Albany.Edu> rds95 at leah.Albany.Edu (Robert Seals) writes:
> I got a question. Suppose I know the name of a function, like so:
> 
> 	char *f = "A_Function";
> 
> and I got a function of the same name like so:
> 
> 	void A_Function(void) { /* stuff */ }
> 
> 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.

You can look up the name in the program's symbol table, cast the value of
the symbol to "pointer to function returning ...", and call it.
Of course, this requires that your program can determine it's file name,
that the file is readable, that it has a symbol table, that the function
has not been declared as "static", etc., but you get the idea.

--
    Oliver Laumann, Technical University of Berlin, Germany.
    ...!pyramid!tub!net   or   net at TUB.BITNET
    ...!mcvax!unido!tub!net



More information about the Comp.lang.c mailing list