Is it possible to print Hollerith constants when compiling with gfortran (GNU)? I know the compiler supports them in assignments, data statements etc, but I’m struggling to print them to the screen. I know I could use Character or Transfer instead, but I’m specifically interested in this particular question.
Hi @Zrillo, welcome to the forum.
Yes, it is possible, here is an example:
PROGRAM print_hollerith
WRITE(*, '(A)') 4HTEST
END PROGRAM print_hollerith
This will print TEST
to standard output: Compiler Explorer.
Brilliant! Thank you. And thanks for the warm welcome!
Out of history-inspired curiosity: what is your interest in holleriths? They are an antiquated feature in Fortran and have just about zero flexibility.
Plus I believe they are no longer an official part of the language if I remember correctly. Weren’t they removed in F2003 over 20 years ago now.
It began from wanting understand the source code of early games like Advent, and grew from there. I find it easier to read old source code if I am fluent in writing it too. Being from a country whose language was banned and destroyed by colonials, I also just have a kind of instinctual drive to keep old languages and discarded aspects of language alive. They have often been discarded for reasons other than it seems.
Understandable Two remarks:
- In secondary school I learned both Latin and (some) classical Greek, so I do have a weak spot for old languages as well.
- I have written a document on old language constructs in Fortran (or better: FORTRAN). It may or may not be of use to you. You can find it here: GitHub - arjenmarkus/old-programming-idioms: Explain old-style programming idioms used in FORTRAN 77 programs
Hollerith constants were removed as of FORTRAN 77. In FORTRAN 66, they are numeric values, since F66 did not have the character type. The only remnant of them in the language is the H format edit descriptor. @certik 's example is non-standard as a Hollerith constant is not of type character - this would have been OK in F66. Of course, most compilers continue to support them as extensions - please don’t propagate them in your code.