2. LANGUAGE EXTENSIONS
Fortran 77 includes almost all of Fortran 66 as a subset.
We describe the differences briefly in the Appendix.
The most important additions are a character string data type,
file-oriented input/output statements, and random access I/O.
Also, the language has been cleaned up considerably.
In addition to implementing the language specified in the new Standard,
our compiler implements a few extensions described in this section.
Most are useful additions to the language.
The remainder are extensions
to make it easier to communicate with C procedures
or to permit compilation of
old (1966 Standard) programs.
2.1. Double Complex Data Type
-
The new type
double complex
is defined.
Each datum is represented by a pair of double precision real variables.
A double complex version of every
complex
built-in function is provided.
The specific function names begin with z instead of c.
2.2. Internal Files
-
The Fortran 77 standard introduces ``internal files'' (memory arrays), but
restricts their use to formatted sequential I/O statements.
Our I/O system also permits internal files to be used
in direct and unformatted reads and writes.
2.3. Implicit Undefined statement
-
Fortran 66 has a fixed rule that the type of a variable that does not appear in a type statement
is
integer
if its first letter is
i, j, k, l, m or n,
and
real
otherwise.
Fortran 77 has an
implicit
statement for overriding this rule.
As an aid to good programming practice, we permit an additional type,
undefined.
The statement
-
implicit undefined(a-z)
turns off the automatic data typing mechanism,
and the compiler will issue a diagnostic for each variable that is used but does
not appear in a type statement.
Specifying the
-u
compiler flag is equivalent to beginning each procedure with this statement.
2.4. Recursion
-
Procedures may call themselves, directly or through a chain of other procedures.
2.5. Automatic Storage
-
Two new keywords are recognized,
static
and
automatic.
These keywords may appear as ``types'' in type statements and in
implicit
statements.
Local variables are static by default;
there is exactly one copy of the datum, and its value is retained between calls.
There is one copy of each variable declared
automatic
for each invocation of the procedure.
Automatic variables may not appear in
equivalence,
data,
or
save
statements.
2.6. Source Input Format
-
The Standard expects input to the compiler to be in 72 column format:
except in comment lines,
the first five characters are the statement number, the next is the continuation character,
and the next sixty-six are the body of the line.
(If there are fewer than seventy-two characters on a line, the compiler pads it with blanks;
characters after the seventy-second are ignored).
-
In order to make it easier to type Fortran programs,
our compiler also accepts input in variable length lines.
An ampersand (``&'') in the first position of a line indicates a continuation
line; the remaining characters form the body of the line.
A tab character in one of the first six positions of a line signals the
end of the statement number and continuation part of the line;
the remaining characters form the body of the line.
A tab elsewhere on the line is treated as another kind of blank by the
compiler.
-
In the Standard, there are only 26 letters -- Fortran is a one-case language.
Consistent with ordinary
UNIXsystem usage, our compiler expects lower case input.
By default, the compiler converts all upper case characters to lower case except those inside character constants.
However, if the
-U
compiler flag is specified, upper case letters are not transformed.
In this mode, it is possible to specify external names with upper case letters in them,
and to have distinct variables differing only in case.
Regardless of the setting of the flag,
keywords will only be recognized in lower case.
2.7. Include Statement
-
The statement
-
include 'stuff'
is replaced by the contents of the file
stuff.
includes may be nested to a reasonable depth, currently ten.
2.8. Binary Initialization Constants
-
A
logical,
real,
or
integer
variable may be initialized in a
data
statement
by a binary constant, denoted by a letter followed by a quoted string.
If the letter is b, the string is binary, and only zeroes and ones are permitted.
If the letter is o, the string is octal, with digits 0-7.
If the letter is z or x, the string is hexadecimal, with digits 0-9, a-f.
Thus, the statements
-
integer a(3)
data a / b'1010', o'12', z'a' /
initialize all three elements of
a
to ten.
2.9. Character Strings
-
For compatibility with C usage, the following backslash escapes are recognized:
-
\n newline
\t tab
\b backspace
\f form feed
\0 null
\' apostrophe (does not terminate a string)
\" quotation mark (does not terminate a string)
\\ \
\x x, where x is any other character
Fortran 77 only has one quoting character, the apostrophe.
Our compiler and I/O system recognize
both the apostrophe ( ' ) and the double-quote ( " ).
If a string begins with one variety of quote mark, the other may be embedded within it
without using the repeated quote or backslash escapes.
-
Every unequivalenced scalar local character variable and every character string constant is aligned
on an
integer
word boundary.
Each character string constant appearing outside a
data
statement is followed by a
null character to ease communication with C routines.
-
Fortran 77 does not have the old Hollerith (nh)
notation,
though the new Standard recommends implementing the old Hollerith feature
in order to improve compatibility with old programs.
In our compiler, Hollerith data may be used in place of character string constants,
and may also be used to initialize non-character variables in
data
statements.
2.11. Equivalence Statements
-
As a very special and peculiar case,
Fortran 66 permits an element of a multiply-dimensioned array to be represented by
a singly-subscripted reference in
equivalence
statements.
Fortran 77 does not permit this usage, since
subscript lower bounds may now be different from 1.
Our compiler permits single subscripts in
equivalence
statements,
under the interpretation that all missing subscripts are equal to 1.
A warning message is printed for each such incomplete subscript.
2.12. One-Trip DO Loops
-
The Fortran 77 Standard requires that the range of a
do
loop not be performed
if the initial value is already past the limit value,
as in
-
do 10 i = 2, 1
The 1966 Standard stated that the effect of such a statement was undefined,
but it was common practice that the range of a
do
loop would be performed
at least once.
In order to accommodate old programs, though they were in violation of the 1966 Standard,
the
-onetrip
compiler flag causes non-standard loops to be generated.
2.13. Commas in Formatted Input
-
The I/O system attempts to be more lenient than the
Standard when it seems worthwhile.
When doing a formatted read of non-character variables,
commas may be used as value separators in the input record,
overriding the field lengths given in the format statement.
Thus,
the format
-
(i10, f20.10, i4)
will read the record
-
-345,.05e-3,12
correctly.
2.14. Short Integers
-
On machines that support halfword integers,
the compiler accepts declarations of type
integer*2.
(Ordinary integers follow the Fortran rules about occupying the same
space as a REAL variable; they are assumed to be of C type
long int;
halfword integers are of C type
short int.)
An expression involving only objects of type
integer*2
is of that type.
Generic functions return short or long integers depending on the actual types of their arguments.
If a procedure is compiled using the
-I2
flag, all small integer constants will be
of type
integer*2.
If the precision of an integer-valued intrinsic function is not determined by the generic function rules,
one will be chosen that returns the prevailing length
(integer*2 when the -I2 command flag is in effect).
When the
-I2
option is in effect, all quantities of type
logical
will be short.
Note that these short integer and logical quantities do not obey the standard rules for storage association.
2.15. Additional Intrinsic Functions
-
This compiler supports all of the intrinsic functions specified in the Fortran 77 Standard.
In addition, there are functions for performing bitwise Boolean operations
(
or,
and,
xor,
and
not)
and for accessing the
UNIXcommand arguments
(
getarg
and
iargc
).