Xref: utzoo comp.lang.c:39394 comp.lang.fortran:5426 comp.unix.questions:31499 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!agate!violet.berkeley.edu!jerry From: jerry@violet.berkeley.edu (Jerry Berkman;217E;24804;;ZA78) Newsgroups: comp.lang.c,comp.lang.fortran,comp.unix.questions Subject: Re: Calling C from FORTRAN under Unix Message-ID: <1991May20.232613.19802@agate.berkeley.edu> Date: 20 May 91 23:26:13 GMT Article-I.D.: agate.1991May20.232613.19802 References: <5343@dftsrv.gsfc.nasa.gov> <1991May17.163421.11604@unixg.ubc.ca> <5360@dftsrv.gsfc.nasa.gov> Sender: root@agate.berkeley.edu (Charlie Root) Organization: University of California, Berkeley Lines: 40 In article <5360@dftsrv.gsfc.nasa.gov> packer@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