Ancient Fortranism for encoding a string literal in a Fortran program^Wcode. This is something so ugly it makes other Fortran kluges, like the arithmetic IF, seem like paragons of software engineering.

Imagine a language without a real string type. You still want to write output, though. How can you do it? More importantly, how can you keep your compiler small yet allow any string when operating off punched cards (C strings don't, because they can't contain null characters, and quoting is probably too complex...)? Most importantly, of course, you must preserve orthogonality. With the FORMAT statement, which makes C's printf format strings seem like a very good idea.

Easy! Think Pascal strings -- length counted. Of course, since strings will only be appearing in the source code, you don't really need to store the length anywhere. Besides, we want to keep the parser simple. (Only we don't! Hollerith descriptors are one of the misfeatures that make Fortran not be a context free language, not even remotely...)

Let's solve all our problems, by dumping them on the programmer. To print Hello, world!, just do this:

      WRITE (*, 123)
 123  FORMAT (12HHello world!)
      END
Notice the non-executable FORMAT statement, which just tells WRITE what to write. And note the string literal "Hello world!". Which just happens to be 12 characters long.

For an easy exercise, add the missing comma into the Hollerith descriptor...

We're talking FORTRAN66 here, at the latest. But of course every modern Fortran compiler will still be delighted to oblige... They do have much better ways to specify string literals in FORMATs, but they still support good old Hollerith.

Log in or register to write something here or to contact authors.