Question to gfortran and C

Tobias.Schlueter@Physik.Uni-Muenchen.DE Tobias.Schlueter@Physik.Uni-Muenchen.DE
Tue Jan 17 10:08:00 GMT 2006


Quoting "j.ahlschlaeger" <j.ahlschlaeger@fz-juelich.de>:
> How compile I a fortran program with gfortran, where I use a C function
> from ctype.h or math.h.

I assume you're trying to call a C function from Fortran?  In that case you need
to introduce an interface function which translates between C calling
conventions and Fortran calling conventions.  Say, you want to call
 int cfunc (double x, int y);
you would then declare a function
 int cfunc_ (double * x, int *y)
 {
     return cfunc (*x, *y);
 }
and in your Fortran program you would now be able to call a function with the
following interface
 INTERFACE
   INTEGER FUNCTION cfunc (x, y)
     REAL*8 x
     INTEGER y
   END FUNCTION
 END INTERFACE

I'm sure you'll find more details on google.

Cheers,
- Tobi



More information about the Fortran mailing list