Go to the first, previous, next, last section, table of contents.


Generating Skeletons and Prototypes with f2c

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 example, `fred.f') of dummy Fortran skeletons comprising just the declaration of the routine(s) and dummy arguments plus `END' statements. Then run f2c on file `fred.f' to produce `fred.c' 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 interfaces with f2c conventions, such as not using doublereal as the return type of a REAL FUNCTION.)

f2c also can help with calling Fortran from C, using its `-P' option to generate C prototypes appropriate for calling the Fortran.(1) 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 `joe.P' containing prototype information. #include this in the C which has to call the Fortran routines to make sure you get it right.

See section Arrays (DIMENSION), for information on the differences between the way Fortran (including compilers like g77) and C handle arrays.


Go to the first, previous, next, last section, table of contents.