Mail Archives: djgpp/1996/09/13/15:37:12
| Xref: | news2.mv.net comp.os.msdos.djgpp:8594
|
| From: | Erik Max Francis <max AT alcyone DOT com>
|
| Newsgroups: | comp.os.msdos.djgpp
|
| Subject: | Re: function pointers
|
| Date: | Thu, 12 Sep 1996 08:06:15 -0700
|
| Organization: | Alcyone Systems
|
| Lines: | 34
|
| Message-ID: | <323826E7.21719469@alcyone.com>
|
| References: | <517hq2$hqp AT news DOT ghgcorp DOT com>
|
| NNTP-Posting-Host: | newton.alcyone.com
|
| Mime-Version: | 1.0
|
| To: | djgpp AT delorie DOT com
|
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Jeff wrote:
> I know there is a way to do this in DJGPP 2.0, can somebody just tell me
> how?
This will work in any ANSI C compiler:
/* funcptr is a function pointer which takes two ints and has no return */
typedef void (*funcptr)(int, int);
/* Here's a prototype for a real function which will assign to our function
pointer */
extern void sampleFunction(int x, int y);
/* Declare a function pointer */
funcptr fp;
/* Assign it -- any reference to a function name without the call operator
() decays to a function pointer of that type */
fp = sampleFunction;
/* Now call it */
fp(12, 13);
/* Note that the following is also exactly equivalent to the above;
dereferencing function pointers is ignored, but is sometimes useful if
you want to emphasize that it's a function pointer you're using */
(*fp)(12, 13);
--
Erik Max Francis, &tSftDotIotE http://www.alcyone.com/max/ max AT alcyone DOT com
San Jose, California ICBM 37 20 07 N 121 53 38 W R^4: the 4th R is respect
"Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_
- Raw text -