DCL: MATH1: Summary: FORTRAN77 Standard
In the previous section, mixing floating-point variables, integer variables, and
logical variables presented no problems. This is because the FORTRAN
standard defines that all 3 of these data types "occupy a single
numerical memory unit." However, in many implementations in which 1
character is defined as "occupying 1 character memory unit," "1
numerical memory unit" usually corresponds to "1 word" of 32
bits, and "1 character memory unit" usually corresponds to
"1 byte," or 8 bits, although they are not actually defined in the
standards. Therefore, associating a character-type variable and another variable
type with an EQUIVALENCE statement is prohibited by standard, because it is
unknown how many "character memory units" a "numerical memory
unit" would correspond to.
This is not restricted to only the standard. In an implementation stated
above where 1 word corresponds to 4 bytes, associating "numerical memory
units" with "character memory units" may cause trouble even
when the user has considered their relationship. This is because a
character-type variable may take an arbitrary length in units of
character, so the treatment of character variables may be quite different
from that of other variables (floating-point number, integers, logical variables).
Especially, the delivery of arguments of subroutines is different in many cases.
In the FORTRAN66, there were no character-type variables, and characters were
treated as a sequence of character codes (integers). (4 characters were treated
as 1 integer.) Therefore, character strings could only contain 4 characters and
it was inconvenient. Character-type variables were officially acknowledged from FORTRAN77, and it became possible to handle character strings with arbitrary
lengths and it became very convenient. However, it did have negative
sides, and presented the above restrictions. But when we consider that in many
compilers, it is possible to associate character-type variables with other
variables types, this may also be considered a form of a dialect.
In fields that handle actual observation data, most data consists of both
characters and numbers, so the EQUIVALENCE statement has been used
traditionally. But it should be noted that some compilers do not allow such associations.
Furthermore, character-type variables are different from other types, in that is is forbidden to write identical character elements on the left and right-hand side of expressions (3rd line).
CHARACTER*12 CX CX = 'DENNOU' CX = CX(1:6)//'DENNOU'
In all other types of variables, such assignment statements are allowed, so one may write the above expression from habit. In this case, the following expression should be used.
CHARACTER*12 CX CX = 'DENNOU' CX(7:12) = 'DENNOU'