Path: utzoo!attcan!uunet!cs.utexas.edu!know!samsung!uakari.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!jato!csi!mwette From: mwette@csi.JPL.NASA.GOV (Matt Wette) Newsgroups: comp.lang.fortran Subject: Re: Calling a C function from Fortran. Message-ID: <4482@jato.Jpl.Nasa.Gov> Date: 3 Aug 90 14:01:44 GMT References: <1990Aug2.191231.11783@portia.Stanford.EDU> <2425@l.cc.purdue.edu> Sender: news@jato.Jpl.Nasa.Gov Reply-To: mwette@csi.JPL.NASA.GOV (Matt Wette) Lines: 35 In article <2425@l.cc.purdue.edu>, cik@l.cc.purdue.edu (Herman Rubin) writes: |> In article <1990Aug2.191231.11783@portia.Stanford.EDU>, volovich@dendrite.Stanford.EDU (Gene Volovich) writes: |> > I'm calling a C function from a FORTRAN program on an RT running AOS, and |> > using the standard C compiler and f77. I actually got this to run, but |> > my question is this: why does there need to be an underscore after the name |> > of the C function I'm calling? Here's my code: |> |> [Code deleted] |> |> I do not know when this was introduced, but unlike the older systems I have |> used, in many a name is not a name. |> |> In all the Unix systems I have seen, if a Fortran program uses xyz for a name |> of a variable, function, subroutine, array, etc., it gets translated into |> _xyz_. Similarly, the C name abc becomes _abc. Thus if Fortran calls the |> function pdq, the C function would have to be (in C) pdq_. Also, Fortran |> calls by reference, and C calls by value. So if Fortran has the argument |> x, it really passes the address of x, and C must use *x to get the value. |> This is more understandable. I see this as a very nice feature in Unix for the following reason: It allows you to use Fortran and C libraries with mixed Fortran and C sources. Once I wrote mixed Fortran and C on a VAX and rand into many problems because many routines in the Fortran and C libraries had matching names. YECH! _____________________________________________________________________ Matthew R. Wette | Jet Propulsion Laboratory, 198-326 mwette@csi.jpl.nasa.gov | 4800 Oak Grove Dr, Pasadena,CA 91109 ---------------------------------------------------------------------