Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!ames!sgi!shinobu!odin!galois!bennett From: bennett@galois.sgi.com (Jim Bennett) Newsgroups: comp.sys.sgi Subject: Re: Changing function transfer addresses Message-ID: <7323@odin.corp.sgi.com> Date: 6 May 90 04:59:49 GMT References: <9005032021.AA01918@mcirps2.med.nyu.edu> Sender: news@odin.corp.sgi.com Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 44 karron@nyu.edu (Dan Karron) writes: > I want to make an array of function calls, and assign the > function call addresses into the array, and then pick the > function to be executed by the value in i. If I understand you correctly, you do it like this: ------------------------------------------------------------------------------- /* Define the functions. */ int func1 () {} int func2 () {} int func3 () {} /* functab is an array of pointers to functions. Notice that all of */ /* the functions must be the same type (type int in this case). */ int (*functab [3]) (); main () { int i; /* The following stores the addresses of the three functions in the */ /* table. Note that functions, like arrays, yield their address when */ /* referenced by name only. You could also build the table at compile */ /* time, which would be more efficient. */ (functab [0]) = func1; (functab [1]) = func2; (functab [2]) = func3; /* Then to call a function from the table, given an index, i, just do */ /* the following: */ (*functab [i]) (); } ------------------------------------------------------------------------------- Jim Bennett (bennett@esd.sgi.com)