C official DOD langauge?
Charles Noren
noren at dinl.uucp
Tue Jun 5 03:20:03 AEST 1990
I wrote a *start* of a list of C advantages and disadvantages
in response to the question:
In article <1990May30.212533.8105 at msuinfo.cl.msu.edu>
scholten at cpsvax.cps.msu.edu (David Scholten cps) writes:
>What are the benefits of using C versus Fortran?
A couple of people responded to me by e-mail noting that I forgot
about some disadvantages of C to Fortran (forgetting was a
generous statement, I didn't know about some of the stuff,
particularly aliasing). So here is a revised
edition of my list, certainly not complete, with additions and
comments welcome.
Thanks to Andrew Mullhaupt (mailrus!uunet!Morgan.COM!amull) and
from a person from Microsoft (whose name I could not locate in
the mail header).
(Caveat: I used Fortran a long time ago - Fortran IV in fact.
Some of these comments may not apply to later additions of
Fortran such as Fortran 77).
C Advantage list:
1. Data Structures (Fortran IV didn't have them).
2. Cleaner code structures. Rarely do you
need labels (as you do in Fortran DO loops, computed
goto's, etc.). You do need lables in C case statements.
3. Data Pointers. Reduces need to copy data which helps
make code faster, allows for reentrant/recursive code,
and the declaration of structures that can be "overlaid"
on memory (useful, for instance, in memory-mapped I/O).
4. Ability to have variable argument lists.
5. Ability to do recursive function calls.
6. Macros.
7. Function pointers. Pointers to functions can be
placed in a table and executed "directly" from the
table.
8. Free form entry of code for C vs. the reserved columns
for Fortran (at least Fortran IV). This allows nicer
indentation style to make the code easier for the
human to read.
C Disadvantage list:
1. Pointers. This will take pure Fortran hackers a little
time to get used to. Pointers are pervasive in C.
2. Perhaps a little less mature math library.
3. Fortran compilers have been around longer and are
generally better at optimization than C compilers.
4. The Fortran language is designed so that compilers
can make useful assumptions for code optimization,
which cannot be made for C compilers. Two examples:
a. Aliasing is not permitted in Fortran.
For instance, if you declare two array arguments in
a Fortran subroutine, those arguments cannot be the
same array. This permits the subroutine to be compiled
with very fast vector instructions (on machines that
support vectorization such as Crays).
b. The C for statement does not have a well defined
"control variable" and thus cannot be automatically
vectorized.
5. Array subscripts in C must start with zero, which for
some is counter intuitive (of course the C programmer
might ask what is so intuitive about starting with
1 ;-)). One person mentioned this can cause optimization
problems by defeating alias optimizations in C.
6. C does not permit multidimensional array parameters of
different sizes.
--
Chuck Noren
NET: ncar!dinl!noren
US-MAIL: Martin Marietta I&CS, MS XL8058, P.O. Box 1260,
Denver, CO 80201-1260
Phone: (303) 971-7930
More information about the Comp.lang.c
mailing list