Calling FORTRAN from C (Was: Ne

flint at gistdev.UUCP flint at gistdev.UUCP
Thu May 11 09:14:00 AEST 1989


Dealing with blank-filled vs null terminated strings, calling conventions,
variable sizes, routine names, etc.  are all a pain.  The biggest pain is
when the system libraries are improperly constructed though. 

An example: The main() routine is in C which calls Fortran routines which
in turn call C routines.  Unfortunately, the Fortran parts use some string
functions that don't exist in the C library, so if you want it to work, you
have to link in the Fortran library.  Can you just add a -lF77?  Wrong,
that gives you a "duplicate function main()" error.  Ok, so you ar the
routines you need out of the Fortran library and link them in explicitly,
and you can make it link and work.  Now you want to put some debug output
into the Fortran codes and guess what: the routines needed aren't
available, and if you try to ar only the .o files out of libF77.a you need,
you eventually end up needing something that is in the same .o file as the
main() routine of libF77. 

The end result is that if I want to do any output at all from the Fortran
code, I have to call a C routine to do it.  All this pain could be avoided
if the genius who created the libF77.a had put the main() routine in it's
own .o all by itself, so that I could just copy the library and remove
main.o and link it.  But if you toss several routines into the same .o
together, then you can't take the extra main() out without taking out
something else that you have to have to do Fortran style I/O. 

Flint Pellett, Global Information Systems Technology, Inc.
1800 Woodfield Drive, Savoy, IL 61874 (217) 352-1165
INTERNET: flint%gistdev at uxc.cso.uiuc.edu
UUCP: {uunet,pur-ee,convex}!uiucuxc!gistdev!flint



More information about the Comp.lang.c mailing list