Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!hascall From: hascall@atanasoff.cs.iastate.edu (John Hascall) Newsgroups: comp.lang.c Subject: Re: Functions pointers and stuff Message-ID: <926@atanasoff.cs.iastate.edu> Date: 29 Mar 89 23:10:04 GMT References: <1715@leah.Albany.Edu> <3182@goofy.megatest.UUCP> Reply-To: hascall@atanasoff.cs.iastate.edu (John Hascall) Organization: Iowa State Univ. Computation Center Lines: 25 In article <3182@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes: >From article <1715@leah.Albany.Edu>, by rds95@leah.Albany.Edu (Robert Seals): >> 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's no portable way. What system are you running? What version >of C? struct { char *f_name; int (*f_func)(); /* if memory serves */ } stuff[] = { {"fubar", fubar}, /* etc ..... */ {"blarg", blarg}, } Then just search stuff[?].f_name for the function you want, and then do: *(stuff[index].f_func)( args... ); (It works faster if it is sorted by name so you can use a binary search.) John Hascall / "More or less, anyhow!"