home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20025 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.4 KB  |  56 lines

  1. Xref: sparky comp.lang.c++:20025 comp.lang.c:20302
  2. Path: sparky!uunet!ukma!darwin.sura.net!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!pawnee.telecom.ksu.edu!news
  3. From: jerry@pawnee.telecom.ksu.edu (Jerry Anderson)
  4. Newsgroups: comp.lang.c++,comp.lang.c
  5. Subject: Re: Pointers to Functions
  6. Date: 28 Jan 1993 08:55:05 -0600
  7. Organization: Kansas State University
  8. Lines: 43
  9. Message-ID: <1k8s49INN8ea@pawnee.telecom.ksu.edu>
  10. References: <1993Jan27.133810.545@vaxc>
  11. NNTP-Posting-Host: pawnee.telecom.ksu.edu
  12.  
  13. acctpu@vaxa.hofstra.edu writes:
  14.  
  15. > I was wondering.  If I define a pointer to a function
  16.  
  17. >     void (*fp)()
  18.  
  19. > How would I get the pointer to *point* to a function, and
  20. > how would I *execute* the function the pointer is pointing
  21. > to.
  22.  
  23. ---------- cut here ----------
  24. /*
  25.  * Just an example of pointers to functions.
  26.  */
  27.  
  28. #include <stdio.h>
  29.  
  30. void foo()
  31. {
  32.     printf("\nAha!  A successful call to foo()!\n\n");
  33. }
  34.  
  35. main()
  36. {
  37.     void (*fp)();
  38.  
  39.     /*
  40.      *  "How would I get the pointer to *point* to a function"?
  41.      */
  42.     fp = foo;
  43.  
  44.     /*
  45.      *  "and how would I *execute* the function the pointer is
  46.      *  pointing to"?
  47.      */
  48.     fp();
  49. }
  50.  
  51. -- 
  52. jerry@telecom.ksu.edu                     Jerry Anderson
  53.                                           Kansas State University
  54. vox: (913) 532-6936                            Telecommunications
  55. fax: (913) 532-7114                       Manhattan  KS  66506
  56.