C vs. FORTRAN (was: What should be added to C)

KW Heuer kwh at bentley.UUCP
Tue May 27 04:29:38 AEST 1986


In article <1594 at ecsvax.UUCP> ecsvax!dgary (D Gary Grady) writes:
>Right now Fortran has four things over C:

Of which I'd like to address the first two.

>o A richer set of floating point operators, including exponentiation and
>  the so-called "in-line" functions (many of which ARE in C).

I think you mean "builtin" rather than "inline".  I don't even consider that
a significant difference, much less an advantage of FORTRAN.  Exponentiation
in general is syntactically neater in FORTRAN but semantically identical on
most machines.  Exponentiation with integer exponents is a problem in C; it
isn't even available as a library function!  When the exponent is constant
(usually 2 or 3 in practice) it could easily be coded inline, but it's not
clear whether that's sufficient justification for making it an operator.

>o A way of passing different-sized multidimensional arrays to the same
>  subroutine.  (For instance, right now it is not possible to write a
>  function in C that will invert a matrix of arbitrary size without use
>  of some "trick," like making the incoming matrix one-dimensional and
>  hard-coding the subscript computation or using arrays of pointers to
>  pointers.)

Again, this is merely a syntactic quibble -- what FORTRAN does is equivalent
to the one-dimensional "trick", but it's hidden from the user.  FORTRAN lets
you use a variable as a bound in an array declaration, in this special case.
That probably wouldn't be too hard to add to C; in fact it might be possible
to generalize it to allow *any* nonstatic array declaration to have variable
size (within reason).

Another advantage of FORTRAN is implicit DO loops in I/O statements, and the
related ability to use (constant, at least) repeat counts in FORMATs.  I had
a program that made this painfully clear when it was translated from FORTRAN
to C.

Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint



More information about the Comp.lang.c mailing list