Passing an array of pointers to functions 
Author Message
 Passing an array of pointers to functions

Can anyone tell me how I can pass an array of pointers to functions? I did
the following in main

double **rk45( double *ic, double tstart, double tend, int n,
               double h, int *size, double (*f)( double *y) );
int main (void)
{
   double ic[ N + 1] = { 0, 1 };
   double (*funct[N])( double *) = { f1 };
   double **ans;
   int solSize = 0, i, j;

   ans = rk45( ic, 0, 1.4, 2, 0.1, &solSize, funct );
                                             ^^^^^^
where fi is
double f1 ( double *ic )
{
   return ( 1 + ic[1] * ic[1] );

Quote:
}

How do I pass funct to rk45?  I tried a bunch of different stuff without
success.  Thanks.

--
Wai Lee



Sat, 16 Oct 1999 03:00:00 GMT  
 Passing an array of pointers to functions

Quote:

> Can anyone tell me how I can pass an array of pointers to functions? I did
> the following in main

> double **rk45( double *ic, double tstart, double tend, int n,
>                double h, int *size, double (*f)( double *y) );
> int main (void)
> {
>    double ic[ N + 1] = { 0, 1 };
>    double (*funct[N])( double *) = { f1 };
>    double **ans;
>    int solSize = 0, i, j;

>    ans = rk45( ic, 0, 1.4, 2, 0.1, &solSize, funct );
>                                              ^^^^^^
> How do I pass funct to rk45?  I tried a bunch of different stuff without
> success.

Hi "Wai Lee",

By adding a pair of "[]" to your prototype for "rk45":
  double **rk45( double *ic, double tstart, double tend, int n,
                 double h, int *size, double (*f[])( double *y) );
                                               ^^^

Stephan



Sun, 17 Oct 1999 03:00:00 GMT  
 Passing an array of pointers to functions

|> >
|> > Can anyone tell me how I can pass an array of pointers to functions? I did
|> > the following in main
|> >
|> > double **rk45( double *ic, double tstart, double tend, int n,
|> >                double h, int *size, double (*f)( double *y) );
|> > int main (void)
|> > {
|> >    double ic[ N + 1] = { 0, 1 };
|> >    double (*funct[N])( double *) = { f1 };
|> >    double **ans;
|> >    int solSize = 0, i, j;
|> >
|> >    ans = rk45( ic, 0, 1.4, 2, 0.1, &solSize, funct );
|> >                                              ^^^^^^
|> > How do I pass funct to rk45?  I tried a bunch of different stuff without
|> > success.
|>
|> Hi "Wai Lee",
|>
|> By adding a pair of "[]" to your prototype for "rk45":
|>   double **rk45( double *ic, double tstart, double tend, int n,
|>                  double h, int *size, double (*f[])( double *y) );
|>                                               ^^^^

   That answers the question that was asked, but I'd be willing to bet
   that it is _not_ what will work for the poster. More than likely,
   what's needed is just:

          ans = rk45( ic, 0, 1.4, 2, 0.1, &solSize, f1 );

   I suspect that Wai Lee is being misled by the '*f' in the prototype
   of 'rk45()' into believing that an _array_ is needed, when what's
   required is just a pointer to a function that the method can call in
   order to calculate (f'rinstance) a derivative at a specified point.

   This might be regarded as a blemish in C's prototyping facility:
   there's no way to specify a _function_ in the argument list -- you
   must always specify a pointer to the function. Of course, it's a
   pointer that actually gets passed, so "truth in advertising" is
   probably a sufficient refutation of this complaint ...

|>
|> Stephan

--
 Ed Hook                              |       Copula eam, se non posit
 Computer Sciences Corporation        |         acceptera jocularum.
 NASA Langley Research Center         | Me? Speak for my employer?...<*snort*>



Mon, 18 Oct 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. passing pointer to a function expecting an array

2. pass a pointer to array of structs to functions

3. passing array of pointers to function

4. Newbie question: Pointer to an array and passing it into a function

5. Passing 2-D pointer to array to function

6. Simple, Pass Pointer of an Array to function

7. function pointers and function pointers array

8. Passing pointers to arrays of pointers....

9. Pointer to function passed to varargs function

10. Novice: Passing a function pointer to a function

11. How to use (pointer to function), and function and pointer to (pointer to function)

12. Prototyping a function passed a pointer to a function

 

 
Powered by phpBB® Forum Software