Path: utzoo!attcan!uunet!husc6!cmcl2!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran Subject: Re: Fortran vs C for computations Message-ID: <3290@lanl.gov> Date: 7 Sep 88 20:04:39 GMT References: <962@amelia.nas.nasa.gov> Organization: Los Alamos National Laboratory Lines: 37 From article <962@amelia.nas.nasa.gov>, by fouts@lemming.nas.nasa.gov.nas.nasa.gov (Marty Fouts): > > I couldn't pass up making a comment here. It has been my experience > that using a preprocessor for Fortran macro expansion is a certain way > of ensuring nonportable code, since there is no standard preprocessor > [...] Write the preprocessor in Fortran. It is now as portable as the Fortran environment is. Besides, my macro expander _never_ produces non-standard code - it only accepts it. Output from my macro expander will compile on any standard conforming Fortran environment. Finally, my main point was that C macros don't add functionality - only textual convenience. My Fortran macros do the same. C does not excel Fortran in this respect. > I am also a large fan of using #define and #ifdef in C for conditional > compilation. When not overused, this is a major win for smoothing > over portability problems and I've missed it many times in trying to > make portable programs in Fortran. #ifdef is an admission that your compiler isn't any good. If the conditional expression is a constant, a normal if statement should be optimized so that code is only generated for the active branch. If the conditional expression is not a constant, it couldn't be used as part of an #ifdef either. #define is either a _parameter_, an inline function, or an inline procedure - the first is already in Fortran, the others are in the proposed 8x extensions. Besides, as I've already pointed out, the functionality of #define can already be provided in a Fortran environment - portably (in fact, the RATFOR preprocessor has its source given in the original software tools document and includes a macro facility nearly identical to C macros - including ifdefs). J. Giles Los Alamos Note: RATFOR isn't the best macro facility for Fortran. But it is an example of a completely portable public domain preprocessor for which the source is readily available to any interested programmer.