home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20053 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.6 KB

  1. Xref: sparky comp.lang.c++:20053 comp.lang.c:20330
  2. Path: sparky!uunet!ukma!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!csn!harpo.uccs.edu!culebra!dbbergac
  3. From: dbbergac@culebra (Dave Bergacker)
  4. Newsgroups: comp.lang.c++,comp.lang.c
  5. Subject: Re: Pointers to Functions
  6. Date: 28 Jan 1993 15:28:26 GMT
  7. Organization: University of Colorado at Colorado Springs
  8. Lines: 35
  9. Message-ID: <1k8u2qINNbqr@harpo.uccs.edu>
  10. References: <1993Jan27.133810.545@vaxc>
  11. NNTP-Posting-Host: culebra.uccs.edu
  12. X-Newsreader: TIN [version 1.1 PL6]
  13.  
  14. acctpu@vaxa.hofstra.edu wrote:
  15. :     I was wondering.  If I define a pointer to a function
  16. : void (*fp)()
  17. :        How would I get the pointer to *point* to a function, and how would I
  18. : *execute* the function the pointer is pointing to.
  19. : Thanks in advance,
  20. : Gary Graffagnino
  21. : ACCGSG@VAXC.HOFSTRA.EDU
  22.  
  23. Well, assuming no parameters to the function, you really want:
  24. void (*fp)(void);
  25. then assuming you have a function of type void with no parameters,
  26. void foo(void);
  27. the assignment is:
  28. fp = foo;
  29. and the execution is:
  30. fp();
  31. BTW this is all ANSI stuff, if you wan't K&R the execution is
  32. something like:
  33. (*fp)();
  34. which is much less transparent to a new user, or other person reading your
  35. code.  I don't know for sure, but you might want to check the FAQ for
  36. this group....
  37.  
  38. --
  39. ___________________________________________________________________________
  40. | Dave Bergacker            |                  |
  41. | dbbergac@culebra.uccs.edu        | "I am NOT a merry man!"         |
  42. | Any opinions expressed are almost    | Lt. Worf, Enterprise Security   |
  43. | certainly not those of UCCS.        | "Have gahk, will travel"      |
  44. ---------------------------------------------------------------------------
  45.