CSE 505 Lecture Notes:
October 10, 1994
Fortran stands for "FORmula TRANslating system".
First proposal: 1954 (at IBM) by John Backus. Work continued for the next
two years; initial release in 1957. At that time, there was much
skepticism about higher-level languages -- Fortran had to be efficient to
These notes primarily concern Fortran IV.
Control structures are based on IBM 704 branch instructions (Backus
initially thought of Fortran as a language for the 704; there would be
somewhat different languages for different machines)
Fortran has an arithmetic if statement ...
IF (EXPR) N1, N2, N3
... which is not that useful (two-way branches more common than three-way).
Later versions of Fortran had a logical if:
IF (A .LT. 5) A=A-1
There could only be a simple statement in the consequent of the IF (but not
a compound statement, such as another IF or a DO loop).
Additionally, Fortran has the GOTO statement:
Note that we can build other control structures from GOTO's:
- computed GOTO:
(30, 40, and 50 are statement numbers)
Drawbacks of the GOTO:
- while loop
- repeat-until loop
- for loop
See Dijkstra's famous letter to the editor: E.W. Dijkstra, "GOTO Statment
Considered Harmful", CACM, 1968 for more on the GOTO controversy.
- not as clear as structured control statements
- harder for compiler to produce good code
- spaghetti-style programming
There have been countless papers and letters since of the form "X
Considered Y" in imitation, e.g.
Rick Hehner, "DO Considered OD" (about Dijkstra's DO .... OD control
The Structure Principle:
The static structure of a program should correspond in a simple way to the
dynamic structure of the corresponding computation.
Control structures such as WHILE, FOR, and IF-THEN-ELSE support the
structure principle; GOTO's do not.
General Features and Problems of FORTRAN
storage layout: statically allocated (hence no recursion)
data types: fixed, built-in set
optional declarations -- if there is no declaration for a variable, it
defaults to INTEGER if the first letter is I-N, otherwise REAL
- integer, float, double precision float, complex, etc.
This is no longer considered a good idea, since, for example, it
doesn't catch typos in variable names.
declarations local in scope to subroutines, main program
common blocks (anonymous and named) allow sharing among subroutines
common blocks provide a type loophole, since the programmer can have an
INTEGER in one subroutine allocated in the same storage location as a REAL
in another subroutine -- hence FORTRAN is
equivalence statements -- another type loophole
FORTRAN syntax is based on fixed format (punch card influence)
blanks ignored (a mistake)
these statements all mean the same thing:
DO 10 I=1,10
D O1 0I=1,1 0
... but this assigns 1.1 to the variable DO10I!
DO 10 I=1.10
no reserved words (also a mistake)
IF (I) = 1 2 3
IF (I) 1,2,3
... the first statement assigns 123 to element I of the array IF, while the
second is an arithmetic IF statement
major win: algebraic expressions
Evolution to subsequent languages:
- Pascal, Modula-2, Ada, etc.