Calling C from FORTRAN under Unix

Jerry Berkman;217E;24804;;ZA78 jerry at violet.berkeley.edu
Tue May 21 09:26:13 AEST 1991


In article <5360 at dftsrv.gsfc.nasa.gov> packer at amarna.gsfc.nasa.gov writes:
>I received 15 e-mail replies to my query, (two since I started
>writing this followup) -- thanks to everyone! Almost all of
>them, with varying degrees of certainty,  suggested appending
>an underscore to the subroutine name in the C source module and
>compiling and linking as usual. This included one reply from an
>Ultrix 4.1 user. 
>
>But we have Ultrix 4.0, (on a VAXStation) and buried in its
>manual is material that tells how to call C from FORTRAN. It
>requires an intermediate language they call "JBL." Underscores
>are irrelevant. 
>
There are two possible Fortran compilers for Ultrix.
The original f77 adds underscores so that "abc" in a Fortran
program becomes "_abc_".  However DEC's VAX Fortran compiler,
fort, converts the letters to uppercase and does not add underscores.
It converts "abc" to "ABC".  Since the C compiler adds an underscore
before each name, you can not link directly to a C procedure from
a Fortran program compiled with DEC's VAX Fortran.

Instead you need to write an interface routine using DEC's
JBL (Jacket Building Language).  The JBL routine is short,
and possibly easy if you know JBL; but a pain if you don't.

In addition to the different names, f77 and fort treat Fortran
character strings differently in argument lists.  For each
character argument, f77 passes two parameters, the address and
length.  I understand fort passes a descriptor which points
to the address and length.  This is probably one reason to use
JBL.

By the way, fort is not the only compiler which doesn't use underscores.
The Cray CFT77 compiler under UNICOS (Cray's version of UNIX) also converts
the name to upper case and does not add any underscores.  But neither
do the Cray C compilers, so you can call the routine "ABC" in C and
link successfully.  I believe the IBM AIX Fortran and C compilers both
just add a period in front of the name, i.e. ".abc".

	- Jerry Berkman, U.C. Berkeley



More information about the Comp.lang.c mailing list