next up previous contents index
Next: Specific Names of Intrinsic Up: Obsolete and Deprecated Features Previous: ENTRY Statement

EQUIVALENCE Statement

 

EQUIVALENCE is a specification statement which causes two or more items (variables or arrays) to be associated with each other, i.e. to correspond to the same area of memory. Character items can only be associated with other character items; otherwise the data types do not have to match. As with common blocks, however, transfer of information is only permitted via associated items if their data types match. A special exception is made for a complex item which is associated with two real ones.

EQUIVALENCE statements can be used fairly safely to provide a simple variable name as an alias for a particular array element or to associate a character variable with an array of the same length. For example:

 
       CHARACTER STRING*80, ARRAY(80)*1 
       EQUIVALENCE (STRING, ARRAY)

This slightly simplifies access to a single character in the string as the form ARRAY(K) can be used instead of STRING(K:K).

The general form of the statement is:

EQUIVALENCE ( v, v, ... v ), ( v, v, ... v ), ...

where each v is a variable, array, array element, or substring. Dummy arguments of procedures (and variables which are external function names) cannot appear. An array name without subscripts refers to the first element of the array. It is illegal to associate two or more elements of the same array, directly or indirectly, or do anything which conflicts with the storage sequence rules. Variables and arrays in common blocks can appear in EQUIVALENCE statements but this has the effect of bringing all the associated items into the block. They can be used to extend the contents of the block upwards, subject to the rules for common block length, but not downwards.

Although the EQUIVALENCE statement does have a few legitimate uses it is usually encountered in programs where the rules of Fortran are broken to obtain some special effect. Programs which do this are rarely portable.


next up previous contents index
Next: Specific Names of Intrinsic Up: Obsolete and Deprecated Features Previous: ENTRY Statement

Mario Storti
Wed Nov 4 19:32:56 ART 1998