Functions pointers and stuff

Gordon Cross crossgl at ingr.com
Thu Mar 30 00:56:47 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.

One way is to read the symbol table from the executable file.  This requires
that you can obtain the name of the file in all cases (someone could rename
your program only to discover that doing so breaks it!!).  The /proc file
system (if you have one) provides an ioctl call to get an open file descriptor
for the file.  Even so, the "strip" command would then break your program...

Simply put, there really is no better way (that I know of anyway) than the
name/function-pointer table lookup you are doing now...
-- 

Gordon Cross             UUCP:      uunet!ingr!crossgl     "all opinions are
111 Westminister Way     INTERNET:  crossgl at ingr.com        mine and not those
Madison, AL 35758        MA BELL:   (205) 772-7842          of my employer."



More information about the Comp.lang.c mailing list