Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!tut.cis.ohio-state.edu!purdue!mentor.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.fortran Subject: Re: Calling a C function from Fortran. Summary: This is how the horror happened Message-ID: <2425@l.cc.purdue.edu> Date: 3 Aug 90 02:13:33 GMT References: <1990Aug2.191231.11783@portia.Stanford.EDU> Organization: Purdue University Statistics Department Lines: 22 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. -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (Internet, bitnet) {purdue,pur-ee}!l.cc!cik(UUCP)