Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!yale!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!lavaca.uh.edu!uhnix1!moray!urchin!p4694.f506.n106.z1.fidonet.org!Lynn.Lively From: Lynn.Lively@p4694.f506.n106.z1.fidonet.org (Lynn Lively) Newsgroups: comp.lang.c Subject: indirect reference/use of procedures Message-ID: <16702.25FE80FA@urchin.fidonet.org> Date: 12 Mar 90 21:58:16 GMT Sender: ufgate@urchin.fidonet.org (newsout1.26) Organization: FidoNet node 1:106/506.4694 - Fulcrum's Edge, Spring TX Lines: 81 In an article of <9 Mar 90 04:51:51 GMT>, cynthia@ucselx.sdsu.edu (cynthia Anderson) writes: cA>From: cynthia@ucselx.sdsu.edu (cynthia Anderson) cA>Date: 9 Mar 90 04:51:51 GMT cA>Organization: San Diego State University Computing Services cA>Message-ID: <1990Mar9.045151.9601@ucselx.sdsu.edu> cA>Newsgroups: comp.lang.c cA> cA>hello cA> cA>i would like to be able to write a procedure that takes as cA>a parameter a procedure name and then using that name cA>calls the procedure. cA> cA>ie runAProcedure(myProcedure) cA> { cA> cA> cA> myProcedure cA> cA> cA>} cA> cA>Is this possible to do in C? Any help or advise is appreciated cA>tho please e-mail responses so the net won't be cluttered. cA> cA>thanks, cA> cA>cynthia anderson cA> cA>or cA> cA> cA>Disclaimer: whenever it was and whenever it happened, i'm sure i cA>wasn't there and it couldn't have been me. cA>t Cynthia, Not only is it possible it's actually fairly easy to do. You need to declare your function in the following form. (* funcname) (); Examples: int (* myfunc)(); void (* myfunc)(); use it in the program like this myfunc (); If it uses parameters simply specify them at call time. myfunc (param1, param2); of course my the declaration is only a pointer so make sure you initialize it to something. Hence you could do this. int (* myprint) () = printf; myprint ("Hello World!\n"); You can also set up tables of them if you like. typedef INTFUNC int (* func)(); INTFUNC func_tab[10]; and later on refer to func_tab[1](); Hope this helps. Your Servant, Lynn