Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!teknowledge-vaxc!sri-unix!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.lang.fortran Subject: Re: Fortran vs C for computations Message-ID: <459@quintus.UUCP> Date: 21 Sep 88 09:04:42 GMT References: <1226@scolex> <3448@lanl.gov> <391@quintus.UUCP> <7029@jhunix.HCF.JHU.EDU> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 66 In article <7029@jhunix.HCF.JHU.EDU> ins_aejs@jhunix.HCF.JHU.EDU (Edward Sullivan) writes: > To say that cpp cannot be usefully applied to Fortran programs >is simply incorrect. I've done it myself. No quibbling about >whether you can call a program that uses #include a Fortran >program. Ambiguity here: it IS possible to write "a" Fortran program which can be used with cpp (which Giles is now affirming, and which surely no-one denies) it is NOT possible to apply cpp usefully to "a" standard Fortran program which already exists (which I have been denying). I thought the example I posted, which showed that a perfectly sensible application of cpp to a perfectly ordinary Fortran text (apart from the #define) yielded *garbage* (well, the Fortran compiler thought it was) was a sufficient proof of my claim that cpp is not GENERALLY applicable to Fortran texts. It certainly isn't applicable to texts which already exist, because it doesn't know that the following three statements are the same in F77: HERE = THERE HERE = THE R E HERE = TH 1 ERE and if there were a macro #define THERE, it would _not_ be expanded in the last two cases. A reasonable application of cpp might be to try to replace calls to a function CDCFNC(X,Y) by calls to VAXFNC(X,Y), but for this reason, it cannot be expected to work in all cases. For real fun, consider #define C 3.0E8 C THIS ONE IS *NOT* THE SPEED OF LIGHT, BUT GUESS WHAT Unfortunately, no cpp that I have used can be used *directly* to write macros which expand into multiple Fortran statements: #define MACRO \ X = 1 \ Y = 2 \ CALL FRED MACRO MACRO END expands to X = 1 Y = 2 CALL FRED X = 1 Y = 2 CALL FRED END as you may discover by trying it yourself. I have had some success with putting semicolons in the macros, e.g. #define MACRO \ X = 1; \ Y = 2; \ CALL FRED and putting the result through a sed(1) filter which turns the semicolons into a new-line and a tab. The bottom line is that if you want to use cpp (which is the *C* pre-processor after all) on Fortran texts, you have to make your Fortran texts conform to the lexical rules of C, as far as you can, and you may have to postprocess the output to make it acceptable to a Fortran processor (even, as I showed in an earlier posting, to a Fortran processor on the same UNIX system). A much better plan, if you want to write Fortran code with the aid of cpp, is, as I said in an earlier posting, to write your source code in Ratfor, which is much more lexically compatible with C and is _designed_ to be used with cpp, and use the Ratfor processor as the back-end to convert cpp's output to Fortran.