home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:20053 comp.lang.c:20330
- Path: sparky!uunet!ukma!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!csn!harpo.uccs.edu!culebra!dbbergac
- From: dbbergac@culebra (Dave Bergacker)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: Pointers to Functions
- Date: 28 Jan 1993 15:28:26 GMT
- Organization: University of Colorado at Colorado Springs
- Lines: 35
- Message-ID: <1k8u2qINNbqr@harpo.uccs.edu>
- References: <1993Jan27.133810.545@vaxc>
- NNTP-Posting-Host: culebra.uccs.edu
- X-Newsreader: TIN [version 1.1 PL6]
-
- acctpu@vaxa.hofstra.edu wrote:
- : 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.
- :
- : Thanks in advance,
- :
- : Gary Graffagnino
- : ACCGSG@VAXC.HOFSTRA.EDU
-
- Well, assuming no parameters to the function, you really want:
- void (*fp)(void);
- then assuming you have a function of type void with no parameters,
- void foo(void);
- the assignment is:
- fp = foo;
- and the execution is:
- fp();
- BTW this is all ANSI stuff, if you wan't K&R the execution is
- something like:
- (*fp)();
- which is much less transparent to a new user, or other person reading your
- code. I don't know for sure, but you might want to check the FAQ for
- this group....
-
- --
- ___________________________________________________________________________
- | Dave Bergacker | |
- | dbbergac@culebra.uccs.edu | "I am NOT a merry man!" |
- | Any opinions expressed are almost | Lt. Worf, Enterprise Security |
- | certainly not those of UCCS. | "Have gahk, will travel" |
- ---------------------------------------------------------------------------
-