Print Hollerith Constant

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.

2 Likes

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.

1 Like

Brilliant! Thank you. And thanks for the warm welcome!

2 Likes

Out of history-inspired curiosity: what is your interest in holleriths? They are an antiquated feature in Fortran and have just about zero flexibility. :innocent:

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.

2 Likes

Understandable :slight_smile: Two remarks:

2 Likes

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.

2 Likes