Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!mintaka!spdcc!dirtydog.ima.isc.com!ispd-newsserver!tuna!randolph From: randolph@tuna.ssd.kodak.com (Gary L. Randolph) Newsgroups: comp.lang.c Subject: Re: Calling IMSL routines (FORTRAN) from C Keywords: C, IMSL, FORTRAN Message-ID: <1991May29.172225.1315@ssd.kodak.com> Date: 29 May 91 17:22:25 GMT References: Sender: news@ssd.kodak.com Organization: Eastman Kodak Lines: 73 In article koft@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 >#include >#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 . . . . . . . .