SuivantPrec.Bas prec.BasNiv. sup.

4.5 Symbolic Names 

Symbolic names can be given to items such as variables, arrays, constants, functions, subroutines, and common blocks. All symbolic names must conform to the following simple rule: the first character of each name must be a letter, this may be followed by up to five more letters or digits. Here are some examples of valid symbolic names:
           I  MATRIX  VOLTS  PIBY4  OLDCHI  TWOX  R2D2  OUTPUT
And here are some names which do not conform to the rules:
COMPLEX(too many letters)
MAX_EL (underscore is not allowed)
2PI (starts with a digit)
Height (lower-case letters are not allowed).
It is best to avoid using digits in names unless the meaning is clear, because they are often misread. The digit 1 is easily confused with the letter I, similarly 0 looks much like the letter O on many devices.

The six-character limit on the length of a symbolic name is one of the most unsatisfactory features of Fortran: programs are much harder to understand if the names are cryptic acronyms or abbreviations, but with only six characters there is little choice. Although many systems do not enforce the limit (and Fortran90 allows names up to 31 characters long), at present the only way to ensure software portability is to keep to it strictly. There is a further problem with items which have an associated data type (constants, variables, arrays, and functions). Unless the data type is declared explicitly in a type statement, it is determined by the initial letter of the name. This may further restrict the choice.

Scope of Symbolic Names 

Symbolic names which identify common blocks and program units of all types are global in scope, i.e. their name must be unique in the entire executable program. Names identifying all other items (variables, arrays, constants, statement functions, intrinsic functions, and all types of dummy argument) are local to the program unit in which they are used so that the same name may be used independently in other program units.

To see the effect of these rules here is a simple example. Suppose your program contains a subroutine called SUMMIT. This is a global name so it cannot be used as the name of global item (such as an external procedure or a common block) in the same executable program. In the SUMMIT subroutine and in any other program unit which calls it the name cannot be used for a local item such as a variable or array. In all other program units, however, including those which call SUMMIT indirectly, the name SUMMIT can be used freely e.g. for a constant, variable, or array.

The names of global items need to be chosen more carefully because it is harder to alter them at a later stage; it can be difficult to avoid name clashes when writing a large program or building a library of procedures unless program unit names are allocated systematically. It seems appropriate for procedures to have names which are verb-like. If you find it difficult to devise sensible procedure names remember that the English language is well stocked with three and four-letter verbs which form a good basis, for example: DO, ASK, GET, PUT, TRY, EDIT, FORM, LIST, LOAD, SAVE, PLOT. By combining a word like one of these with one or two additional letters it is possible to make up a whole range of procedure names.

Reserved Words 

In most computer languages there is a long list of words which are reserved by the system and cannot be used as symbolic names: Cobol programmers, for example, have to try to remember nearly 500 of them. In Fortran there are no reserved words. Some Fortran keywords (for instance DATA, END, and OPEN) are short enough to be perfectly valid symbolic names. Although it is not against the rules to do this, it can be somewhat confusing. The names of the intrinsic functions (such as SQRT, MIN, CHAR) are, technically, local names and there is nothing to prevent you using them for your own purposes, but this is not generally a good idea either. For example, if you choose to use the name SQRT for a local variable you will have more difficulty in computing square-roots in that program unit. It is even more unwise to use the name of an intrinsic function as that of an external procedure because in this case the name has to be declared in an EXTERNAL statement in every program unit in which it is used in this way.

SuivantPrec.Bas prec.HautNiv. sup.