home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:20025 comp.lang.c:20302
- Path: sparky!uunet!ukma!darwin.sura.net!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!pawnee.telecom.ksu.edu!news
- From: jerry@pawnee.telecom.ksu.edu (Jerry Anderson)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: Pointers to Functions
- Date: 28 Jan 1993 08:55:05 -0600
- Organization: Kansas State University
- Lines: 43
- Message-ID: <1k8s49INN8ea@pawnee.telecom.ksu.edu>
- References: <1993Jan27.133810.545@vaxc>
- NNTP-Posting-Host: pawnee.telecom.ksu.edu
-
- acctpu@vaxa.hofstra.edu writes:
-
- > I was wondering. If I define a pointer to a function
-
- > void (*fp)()
-
- > How would I get the pointer to *point* to a function, and
- > how would I *execute* the function the pointer is pointing
- > to.
-
- ---------- cut here ----------
- /*
- * Just an example of pointers to functions.
- */
-
- #include <stdio.h>
-
- void foo()
- {
- printf("\nAha! A successful call to foo()!\n\n");
- }
-
- main()
- {
- void (*fp)();
-
- /*
- * "How would I get the pointer to *point* to a function"?
- */
- fp = foo;
-
- /*
- * "and how would I *execute* the function the pointer is
- * pointing to"?
- */
- fp();
- }
-
- --
- jerry@telecom.ksu.edu Jerry Anderson
- Kansas State University
- vox: (913) 532-6936 Telecommunications
- fax: (913) 532-7114 Manhattan KS 66506
-