Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!pt.cs.cmu.edu!o.gp.cs.cmu.edu!VACATION.VENARI.CS.CMU.EDU!mwm From: mwm@VACATION.VENARI.CS.CMU.EDU (Mark Maimone) Newsgroups: comp.lang.fortran Subject: Re: f2c bug Message-ID: <1991Apr5.175633.18864@cs.cmu.edu> Date: 5 Apr 91 17:56:33 GMT References: <4846@dirac.physics.purdue.edu> Sender: netnews@cs.cmu.edu (USENET News Group Software) Reply-To: mwm@VACATION.VENARI.CS.CMU.EDU (Mark Maimone) Organization: Carnegie Mellon University Lines: 35 In article <4846@dirac.physics.purdue.edu>, piner@maxwell.physics.purdue.edu (Richard Piner) writes: |> Looks like I have found a little bug in f2c. Of course, it took a |> routine from NR to break it. Here it is. Always double check code |> before using it. [code illustrating REAL FUNCTION H being referenced before declared] F2c compiles functions one at a time, sequentially. During the first pass through the program, since H has only been declared EXTERNAL, f2c assumes that it refers to a subroutine rather than a function; how could it infer anything else? Fortunately, there is a mechanism for handling this situation (forward-referencing within a single file). Run f2c once with the -P option; this will generate a prototype file. Then run it again, naming both foo.f and foo.P on the command line. You'll find that it corre ctly types H as a doublereal function. % f2c -P foo.f . . Rerunning "f2c -P ... foo.f foo.P" may change prototypes or declarations % f2c -P foo.f foo.P . . % grep h_ foo.c extern doublereal h_(); qgausx_((E_fp)h_, x1, x2, ss); doublereal h_(real *xx) } /* h_ */ % man f2c .............................................. File names that end with `.p' or `.P' are taken to be prototype files, as produced by option `-P', and are read first. ............................................... Looks like you have found a little idiosyncracy of Fortran. Always read the man page before using software. -- ---------------------------------------------------------------------- Mark Maimone phone: (412) 268 - 7698 Carnegie Mellon Computer Science email: mwm@cs.cmu.edu grad student, vocal jazz and PDQ Bach enthusiast