address of function

William Davidsen davidsen at sungod.crd.ge.com
Wed Jun 14 00:44:14 AEST 1989


|From: dooley at helios.toronto.edu (Kevin Dooley)
|Subject: array of pointers to functions
|Message-ID: <822 at helios.toronto.edu>
|Date: 12 Jun 89 16:40:18 GMT
|Organization: University of Toronto Physics/Astronomy/CITA Computing Consortium

|I had a clever idea last night for a completely general routine to
|numerically solve a system of N coupled first order differential
|equations simultaneously using a Runge-Kutta algorithm.  The only
|way I can think of to conveniently pass an unspecified number of
|pointers to functions is to construct an array of pointers to the
|individual functions.  Imagine my alarm at discovering that this
|is not legal.  Why not?  Can anybody help me out with this little
|puzzle?

|From: maart at cs.vu.nl (Maarten Litmaath)
|Subject: address of function
|Message-ID: <2700 at solo8.cs.vu.nl>
|Date: 6 Jun 89 17:37:09 GMT
|Organization: V.U. Informatica, Amsterdam, the Netherlands

|
|Why weren't function pointers handled the way below?
|
|	int	foo(), (*bar)() = &foo;

The following seem to work portably, and would satisfy the two questions
aboue.

/* function and pointer to it */
int foo(), (*bar)() = foo;		/* bar is pointer to foo */

/* vector of pointers to proc */
int curley(),
    larry(),
    moe();
int (*procvect[])() = { curley, larry, moe };

demo() {
  int k;
  for (k=0; k < 3; ++k)
    (*procvect[k])(k);
}


Sure hope this helps you guys. I may have misunderstood the questions,
of course.
	bill davidsen		(davidsen at crdos1.crd.GE.COM)
  {uunet | philabs}!crdgw1!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list