Next: Assignment
Up: Declaration of Variables
Previous: General Form of Declarations
  Contents
In Fortran implicit declarations are allowed.
Suppose we did not declare the variables I, J, X, Y
but used them somewhere in the program.
The Fortran compiler will not complain; rather, it will automatically
declare I, J as integers and X, Y as reals. The
rule is that undeclared variables which have the first letter
I, J, K, L, M
or N are considered INTEGER-s, and
undeclared variables which start in A through H and
O through Z are
considered REAL-s. The automatic declarations based on implicit types
are called implicit declarations. Some fourty years ago programmers
found it cumbersome to explicitly declare all the variables all the time !
In F90 implicit declarations are permitted, but undesirable.
In general, their use is a very bad programming habit, as it can mask
programming errors, and can negatively impact future software development and
maintainance. For example, a misspelling
of a variable name will result in a new variable declaration,
which can be further assigned etc, with the user
being totally unaware.
An example (from A.C. Marshall) is
do30i = 1.100
<statements>
30 continue
Instead of a DO loop, because of the misprints, we will end
up with a new real variable, do30i.
In consequence, we will always disable the implicit declarations
by placing the command
implicit none
as the first line after any USE
statements (i.e. before the declarations sequence). With this command in place,
the existence of
variables that are not explicitly declared will lead to a copilation error.
Next: Assignment
Up: Declaration of Variables
Previous: General Form of Declarations
  Contents
Adrian Sandu
2001-08-26