
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*>