Calling FORTRAN from C (Was: Need matrix inversion C routine).

Guy Harris guy at auspex.auspex.com
Wed May 3 17:36:24 AEST 1989


>There are two problems.  Each implementation of a language will have its
>calling sequence.  This problem is unavoidable, and can be a major headache.

...

>The bigger problem is names.

No, there are at least three problems.  The third problem is the
representation of the language's data types, unless you consider that a
subclass of the first problem.  Passing a C character string to a
routine expecting a FORTRAN character string may not work, nor will
passing an integer value by reference, FORTRAN-style, to a routine
expecting it to be passed by value, C-style.

>It should be considered essential that any user be able to access any
>object program compiled by any processor by proper use of the calling
>sequence and return, and this means knowing the system name of the program
>and being able to instruct the compiler that a program with that name is
>to be called.

Well:

	1) that's not something within the purview of either the C or
	   FORTRAN standard, since it requires particular implementation
	   choices to be made for both languages; it falls between two
	   chairs, and touches on an area that standards committees
	   often try to avoid constraining, namely implementations. 
	   It's not within the purview of POSIX, either.

	2) given the "third problem", you may have to write a "jacket"
	   routine to translate data types, which means that it may not
	   necessarily be useful merely to patch up the name-space
	   problem, since you can't just call, say, the UNIX "open"
	   routine from FORTRAN in the same way you can call it from C.

I don't have Stu Feldman's paper on F77 handy, so I don't know if he put
in the prepended underscore, in part, to allow you to have a jacket for
the C routine "foobar" written in C and called "foobar_" from within C
and thus "foobar" from within FORTRAN, that does any requisite data type
translations.



More information about the Comp.lang.c mailing list