home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!prism!xray.gatech.edu!cc100aa
- From: cc100aa@xray.gatech.edu (Ray Spalding)
- Newsgroups: comp.lang.c
- Subject: Re: How to call procedure with a variable?!
- Keywords: C VARIABLE PROCEDURE
- Message-ID: <67971@hydra.gatech.EDU>
- Date: 10 Sep 92 19:36:37 GMT
- References: <1992Sep10.143705.15262@galileo.cc.rochester.edu>
- Sender: news@prism.gatech.EDU
- Organization: Georgia Institute of Technology
- Lines: 33
-
- In article <1992Sep10.143705.15262@galileo.cc.rochester.edu> eric@prodigal.psych.rochester.edu (Eric Hansen) writes:
- >I'd like to be able to call a procedure based on the contents of a variable.
- >For instance, if my variable GOTOPROC is equal to "GetNewSearch(X,Y,Z)", then
- >I'd like to somehow say GOTOPROC and have it perform the GetNewSearch
- >routine.
-
- You can just declare a variable of type pointer to function, and
- assign (compatible) declared functions to it. For example:
-
- #include <stdio.h>
-
- int
- getnewsearch(int x, int y, int z)
- {
- return x + y + z;
- }
-
- int (*gotoproc)(int x, int y, int z);
-
- int
- main()
- {
- int t;
-
- gotoproc = getnewsearch;
- t = gotoproc(1,2,3);
- printf("%d\n",t);
- return 0;
- }
- --
- Ray Spalding, Office of Information Technology
- Georgia Institute of Technology, Atlanta Georgia, 30332-0715
- Internet: ray.spalding@oit.gatech.edu (NeXT Mail accepted)
-