Calling IMSL routines (FORTRAN) from C
Gary L. Randolph
randolph at tuna.ssd.kodak.com
Thu May 30 03:22:25 AEST 1991
In article <May.29.12.00.35.1991.16903 at elbereth.rutgers.edu> koft at elbereth.rutgers.edu (Dan Koft) writes:
>Please help me if you can. I have a C program that I want to call an
>IMSL routine called QDAGI, the code in FORTRAN looks like:
> CALL QDAGI(F, BOUND, INTERV, ERRABS, ERRREL, RESULT, ERREST)
...stuff deleted...
>I have tried all the ways I could think of to call this function
>without proper results. Below is the test program from the IMSL
>manual as I have translated it to C.
>#include <stdio.h>
>#include <math.h>
>#define Abs(x) ( (x)>0? (x) : (-x))
>double F(double x);
>extern void qdagi(double *F(), double *bound, int *interv, double *errabs,
> double *errel, double *result, double *errest);
**********************^^^^^^^^^^^^^^^^^^^^****************
First, your declaration of the formal argument, F, is incorrect.
What you want is to declare F as pointer to function taking/returning double.
extern void qdagi(double (*F)(double), ...rest as above)
The parentheses are NOT optional!
>main()
>{
>double abs,bound,errabs,errest,error,errrel,exact,ppi,result;
>int interv = 1;
>bound = 0.0;
>errabs = 0.0;
>errrel = 0.001;
>qdagi((&)F(),&bound,&interv,&errabs,&errrel,&result,&errest);
>/* The above line is where I believe the problem lies*/
Yes, this is a problem. To pass the address of the function, you can pass
either F or &F (the difference has recently been discussed here or .c++)
So, the call would be:
qdagi(F, ...same as before);
To provide a simpler, yet silly, example:
double f(double x){ printf("%s %lf", "\nThe double: ", x); return x;}
void fun(double (*F)(double), double a){printf("%s %lf","\nThe DOUBLE: ",(*F)(a));}
main(){ fun(f,55);}
which results in:
The double: 55.000000
The DOUBLE: 55.000000
Gary Randolph
Eastman Kodak Company
.
.
.
.
.
.
.
.
More information about the Comp.lang.c
mailing list