FLIB2C is a tool to create header files that provide a simple and easy-to-use interface between FORTRAN (library) routines and C. The differences between the FORTRAN and C calling sequences are hidden in a header file that has to be created for every FORTRAN library. FLIB2C simplifies the task of creating a header file.
If one wants to use FORTRAN libraries from C in the UNIX environment, there are several problems: FORTRAN routines always expect pointers to the arguments (call by reference) even if the values are not altered. Calling the FORTRAN routine with a constant value, for example, is not directly possible from C. You first have to assign the constant to a temporary variable and then call the FORTRAN routine with the pointer to that dummy. If the FORTRAN routine has many arguments the resulting C code looks ugly with all the assignments and “&” in front of arguments. In addition it hides the fact that certain arguments are not altered by the FORTRAN routine.
IBM supplies on the RS6000/AIX a header file “essl.h” that simplifies the use of the (FORTRAN) library ESSL from C. The assignment of arguments to temporary variables and the passing of the pointers is hidden from the user using macros of the C preprocessor so that calls to library function can be written in a natural way. The program “flib2c” produces header files that work in the same manner as “essl.h”. Additionally I have corrected a little flaw in “essl.h”: The temporary variables therein are global ones, so if one has several source codes that include “essl.h”, the compiler may generate a “Multiply defined symbol” error. Furthermore, since static variables have a limited scope (i.e. they are local to the file) the compiler can do improved optimizations: It may not keep their values because they can not be used outside and so the global optimizer can delete unused temporaries.
This program is Copyright ? 1993-1995 by Joerg Schoen. Permission to use, copy and distribute this software together with its documentation for any purpose is herby granted provided that the above copyright notice appears in all copies. No fee must be taken for this package. This software is provided “as is” without expressed or implied warranty.
Bug reports, questions, improvements, mail to JÃ¶rg SchÃ¶n
FLIB2C (Fortran Library to C) (23.0 KiB, 1,739 hits)