Fortran advantages over C (revised based on earlier input)

David Hough dgh
Mon Apr 2 17:20:27 PDT 1990


     The following is a list of differences between Fortran-77 and C for
numerical programming; each difference is considered an advantage to at least
some people.  It's an update of one I circulated earlier.  I consider it a
checklist of things to be examined by NCEG; most of the issues have people
working on them.   I will consider NCEG to be successful if it defines a C-
like language that removes most of the reasons for continuing to program in
Fortran.

old code
     There's a lot more old crufty Fortran numeric code than there is in C,
     including a lot of standard mathematical software.  You can build on that
     portably if your application is written in Fortran; you can't rely on
     portable interlanguage linking conventions from C.  This is one issue
     NCEG can't handle directly.  But by removing the others, a substantial
     body numerical C code will evolve.

generic intrinsic operators
     in Fortran rather than libm functions.  They're called "generic intrinsic
     functions" in Fortran but they're really operators.

exponential operators
     x**y and x**i.

no exception handling
     specified in Fortran.

complex types
     known to Fortran compiler rather than user-defined.

dynamic array parameters

lower bounds for arrays
     Although most Fortran arrays have lower bound 1, other lower bounds are
     possible, unlike C.

read/write array
     in one line - all of an array, or parts with implicit do.  Much more
     tedious, and possibly less efficient, with C.

Fortran I/O
     both formatted and unformatted, is much more complicated than C stdio.
     Whether this was good design or not, Fortran systems come with some
     built-in facilities that have to be fabricated in C.

no aliasing
     allowed in Fortran.  Or what is equivalent, optimizers may disregard the
     possibility.

static DO
     Everything needed to run the DO loop is fixed at the outset.  The index
     variable is not allowed to be modified.  You can't jump into the middle
     of a do.

     A C compiler has to do more work to provide equivalent optimization of
equivalent loops, because it must verify at compile time, taking into account
the possibility of aliasing, that the DO parameters are fixed and that no
other funny business occurs.

     Another aspect of this is that DO loops are practically the only Fortran
construct worth examining by automatic parallelizers.  Any sort of C loop is
equally likely to be parallelizable.

     Of course, explicit vector/parallel constructs are better than forcing
compilers to detect parallelism after the fact.



More information about the Numeric-interest mailing list