Hollerith constant
Hollerith constants, named in honor of Herman Hollerith, were used in early FORTRAN programs to allow manipulation of character data.
Early FORTRAN had no
CHARACTER data type, only numeric types. In order to perform character manipulation, characters needed to be placed into numeric variables using Hollerith constants. For example, the constant 3HABC specified a three-character string "ABC", identified by the initial integer representing the string length 3 and the specified Hollerith character H, followed by the string data ABC. These constants were typeless, so that there were no type conversion issues. If the constant specified fewer characters than was possible to hold in a data item, the characters were then stored in the item left-justified and blank-filled.Mechanics
By the FORTRAN 66 Standard, Hollerith syntax was allowed in the following uses:- As constants in
DATAstatements - As constant actual arguments in subroutine
CALLstatements - As edit descriptors in
FORMATstatements
Some authors were of the opinion that for best portability, only a single character should be used per data item. However considering the small memory sizes of machines of the day, this technique was considered extremely wasteful.
Technological obsolescence
One of the major features of FORTRAN 77 was theCHARACTER string data type. Use of this data type dramatically simplified character manipulation in Fortran programs – rendering almost all uses of the Hollerith constant technique obsolete.Hollerith constants were removed from the FORTRAN 77 Standard, though still described in an appendix for those wishing to continue support. Hollerith edit descriptors were allowed through Fortran 90, and were removed from the Fortran 95 Standard.
Examples
The following is a FORTRAN 66 hello world program using Hollerith constants. It assumes that at least four characters per word are supported by the implementation:PROGRAM HELLO1
INTEGER IHWSTR
DATA IHWSTR/4HHELL,4HO WO,3HRLD/
WRITE IHWSTR
STOP
100 FORMAT
END
Besides
DATA statements, Hollerith constants were also allowed as actual arguments in subroutine calls. However, there was no way that the callee could know how many characters were passed in. The programmer had to pass the information explicitly. The hello world program could be written as follows – on a machine where four characters are stored in a word:PROGRAM HELLO2
CALL WRTOUT
STOP
END
C
SUBROUTINE WRTOUT
C
INTEGER IARRAY
INTEGER NCHRS
C
INTEGER ICPW
DATA ICPW/4/
INTEGER I, NWRDS
C
NWRDS = /ICPW
WRITE
RETURN
100 FORMAT
END
Although technically not a Hollerith constant, the same Hollerith syntax was allowed as an edit descriptor in
FORMAT statements. The hello world program could also be written as:PROGRAM HELLO3
WRITE
STOP
100 FORMAT
END
One of the most surprising features was the behaviour of Hollerith edit descriptors when used for input. The following program would change at run time
HELLO WORLD to whatever would happen to be the next eleven characters in the input stream and print that input:PROGRAM WHAT1
READ
WRITE
STOP
100 FORMAT
END