"W.J. Metzger" <[log in to unmask]> wrote:
>> Type declarations, e.g., DoublePrecision d
>> dimensions, e.g., Dimension d(2)
>> common, common /c/ d
>> can appear in any order. But giving a name to a constant, e.g.,
>> Parameter (k=5)
>> must appear before the first use of the named constant, i.e.,
I see your point. The processor needs to go through all the
specification statements to decide what a particular name represents
anyway. Why should an order be imposed for named constants?
I suppose the reason is historical.
In FORTRAN II, there are no type declaration statements, and no COMMON.
Only the DIMENSION statement is used to declare an array, so there is
not much concern here for order of specification statements [Note *1].
FORTRAN IV has type declarations but also retains the DIMENSION
statement. Because of this, it is not possible to give all information
about a name in a single statement. So, separate statements (COMMON,
EXTERNAL, DATA, ...) [Note *2] are used not only for DIMENSION but for
all other bits of information about a name. FORTRAN 66 does not
specify an ordering of specification statements, perhaps aiming for
maximum compatibility between processors [Note *3].
FORTRAN 77 adds the PARAMETER and IMPLICIT statements, and defines
particular ordering of these [Note *4]. Having named constant
values defined before use would make implementation easier.
So, my guess is that FORTRAN 66 allowed arbitrary ordering of
specification statements because it was more concerned with
portability of then existing code, and FORTRAN 77 imposed an
ordering on the new features because it was more concerned with
ease of implementation and with actually having the new features
added to implementations. [Note *5]
[Note *1] In the FORTRAN II Programmer's Reference Manual, it says
"the DIMENSION statement must precede the first appearance of the
variable" (DIMENSION must be specified before use of array), but
"An EQUIVALENCE statement may be placed anywhere in the source program".
So apparently an EQUIVALENCE statement can be placed even after the
executable statements containing the EQUIVALENCEd variables. In the
C is not necessarily an array. When C is not an array, C(5) is "the 4th
storage location in the object program after the cell containing C".
If C is an array of rank three (declared by a DIMENSION statement
preceding or following the EQUIVALENCE statement), C(5) is the 4th storage
location after the cell containing C(1,1,1).
[Note *2] In a DEC PDP-9 FORTRAN IV manual from 1968, it says
"All SPECIFICATION statements must appear before any executable
code generating statement. They must appear in this order:
type statements, DIMENSION statements, COMMON statements, and
EQUIVALENCE statements. EXTERNAL and DATA statements may appear
anywhere after all type statements and before the executable
code generating statements". So this implementation does require
a particular ordering, and code written without this particular
ordering in mind does not run on this processor. The FORTRAN 66
Standard perhaps tried to gain more portability by forcing processors
to relax such restrictions.
[Note *3] The DATA statement is not a "specification statement"
in FORTRAN 66, and a DATA statement must be placed after all the
specification statements. Since Fortran 90, the DATA statement
may be placed among other specification statements, but the type and
array properties must be established before a variable appears
in a DATA statement (or the variable must be a scalar of implicit
type). So the DATA statement always required a particular order
[Note *4] The two other specification statements added in FORTRAN 77,
INTRINSIC and SAVE have no particular ordering defined, perhaps
because they work somewhat like FORTRAN 66's existing specification
[Note *5] There is another issue that is confusing.
The following is not accepted by gfortran and IBM's ifort.
According to the error messages, X here is an implicit REAL variable
and it cannot be in an array-spec, despite the FORTRAN 66 Standard
saying "The appearance of a symbolic name in a type-statement serves
to inform the processor that it is of the specified data type for all
appearances in the program unit" and "In the absence of an explicit
declaration, the type is implied by the first character of the name",
and the FORTRAN 77 Standard saying essentially the same thing
(Sections 8.4 and 4.1.2). The FORTRAN 77 Standard additionally says
(in 4.1.1), "Once a particular name is identified with a particular
type in a program unit, that type is implied for any usage of the name
in the program unit that requires a type". It seems the ordering of
specification statements is significant in this context. I cannot
figure out what the Fortran 2008 Standard says on this matter.
The following is accepted by the two processors (gfortran and ifort):
and so is
The latter would appear at first sight that the ordering of the two
type declarations doesn't matter, but actually the type of N is
determined implicitly, and the INTEGER statement only confirms the
implicit type. Writing IMPLICIT NONE here makes the fragment
On the same two processors (gfortran and ifort),
DOUBLE PRECISION I
declares a common block that has five numeric storage units; the
first four taken up by the double precision array I.
In this context, the processor does look at all three statements
to decide what I and X is, and adding an IMPLICIT NONE has no effect.
[log in to unmask]