Calling functions by address

Charles Noren noren at dinl.uucp
Wed Aug 31 07:58:40 AEST 1988


I'm not sure if I understand, but try something like this:

  typedef void (*func)()  funcarray;

  void func1(), func2(), func3(),...   /* Function Prototypes */

  funcarray addressarray [] = {
    func1, func2, func3,...
  }

  ...and then execute this function to call function by address code:

  void execute (array, code)
  funcarray array[];
  int       code;
  {
    void (*function) ();

    function = array[code];
    (*function)();
  }

  ...the calling code would look like:

  execute (addressarray, code);

I have not tried this, but I have used something very similar for implementing
finite state machines using state/event matrices and it worked quite well.

                          chuck



More information about the Comp.std.c mailing list