Functions pointers and stuff

John Hascall hascall at atanasoff.cs.iastate.edu
Thu Mar 30 09:10:04 AEST 1989


In article <3182 at goofy.megatest.UUCP> djones at megatest.UUCP (Dave Jones) writes:
>From article <1715 at leah.Albany.Edu>, by rds95 at 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!"



More information about the Comp.lang.c mailing list