8. Declarations
8.1. CHARACTER Data Type
-
One of the biggest improvements to the language is the addition of a character-string data type.
Local and
common character variables must have a length denoted by a constant expression:
-
character*17 a, b(3,4)
character*(6+3) c
If the length is omitted entirely, it is assumed equal to 1.
A character string argument may have a constant length,
or the length may be declared to be the same as that of the corresponding actual argument at run time
by a statement like
-
character*(*) a
(There is an intrinsic function
len
that returns the actual length of a character string).
Character arrays and common blocks containing character variables must be packed:
in an array of character variables, the first character of one element must follow the last character of
the preceding element, without holes.
8.2. IMPLICIT Statement
-
The traditional implied declaration rules still hold:
a variable whose name begins with
i, j, k, l, m, or n is of type
integer,
other variables are of type
real,
unless otherwise declared.
This general rule may be overridden with an
implicit
statement:
-
implicit real(a-c,g), complex(w-z), character*(17) (s)
declares that variables whose name begins with an
a ,b, c,
or
g
are
real,
those beginning with
w, x, y,
or
z
are assumed
complex,
and so on.
It is still poor practice to depend on implicit typing, but this statement is an industry standard.
8.3. PARAMETER Statement
-
It is now possible to give a constant a symbolic name, as in
-
parameter (x=17, y=x/3, pi=3.14159d0, s='hello')
The type of each parameter name is governed by the same implicit and explicit rules as for a variable.
The right side of each equal sign must be a constant expression
(an expression made up of constants, operators, and already defined parameters).
8.4. Array Declarations
-
Arrays may now have as many as seven dimensions.
(Only three were permitted in 1966).
The lower bound of each dimension may be declared
to be other than 1 by
using a colon.
Furthermore, an adjustable array bound may be an integer expression involving constants,
arguments, and variables in
common.
-
real a(-5:3, 7, m:n), b(n+1:2*n)
The upper bound on the last dimension of an array argument may be denoted by an asterisk
to indicate that the upper bound is not specified:
-
integer a(5, *), b(*), c(0:1, -2:*)
8.5. SAVE Statement
-
A poorly known rule of Fortran 66 is that local variables in a procedure do not necessarily retain their values between
invocations of that procedure.
At any instant in the execution of a program,
if a common block is declared neither in the currently executing procedure
nor in any of the procedures in the chain of callers,
all of the variables in that common block also become undefined.
(The only exceptions are variables that have been defined in a
data
statement and never changed).
These rules permit overlay and stack implementations for the affected variables.
Fortran 77 permits one to specify that certain variables and common blocks are to retain their
values between invocations.
The declaration
-
save a, /b/, c
leaves the values of the variables
a
and
c
and all of the contents of common block
b
unaffected by a return.
The simple declaration
-
save
has this effect on all variables and common blocks in the procedure.
A common block must be saved in every procedure in which it is declared if the desired effect is to occur.
8.6. INTRINSIC Statement
-
All of the functions specified in the Standard are in a single category,
``intrinsic functions'', rather than being divided into ``intrinsic'' and ``basic external'' functions.
If an intrinsic function is to be passed to another procedure, it must be declared
intrinsic.
Declaring it
external
(as in Fortran 66) causes a function other than the built-in one to be passed.