Node: f2c Skeletons and Prototypes, Next: C++ Considerations, Previous: C Access to Type Information, Up: Interoperating with C and C++
A simple and foolproof way to write
g77-callable C routines--e.g. to
interface with an existing library--is to write a file (named, for
fred.f) of dummy Fortran
skeletons comprising just the declaration of the routine(s) and dummy
f2c on file
fred.f to produce
into which you can edit
useful code, confident the calling sequence is correct, at least.
(There are some errors otherwise commonly made in generating C
such as not using
as the return type of a
f2c also can help with calling Fortran from C, using its
-P option to generate C prototypes appropriate for calling the
If the Fortran code containing any
routines to be called from C is in file
joe.f, use the command
f2c -P joe.f to generate the file
#include this in the C which has to call
the Fortran routines to make sure you get it right.
See Arrays (DIMENSION), for information on the differences
between the way Fortran (including compilers like
C handle arrays.
The files generated like this can also be used for
inter-unit consistency checking of dummy and actual arguments, although
ftnchek tool from ftp://ftp.netlib.org/fortran
or ftp://ftp.dsm.fordham.edu is
probably better for this purpose.