Silverfrost Forums

Welcome to our forums

Hollerith stings again

8 Jul 2020 4:09 (Edited: 8 Jul 2020 9:33) #25931

Hollerith fields in Format statements are 'deleted' in Fortran 95, but Fortran compilers continue it to support it. While working with an old Fortran program with copious instances of Format statements with Hollerith edit descriptors, I discovered a perplexing bug in FTN95 8.63. Here is a bug demonstrator, in fixed form source:

C
      PROGRAM HOLLERITH_BUG
*        1         2         3         4         5         6         7
*23456789 123456789 123456789 123456789 123456789 123456789 123456789 12XXXXXXXX
      WRITE (*,10)
   10 FORMAT (//,2X,39HWARNING: 1) Hollerith fields in Format ,
     + 29Hspecifications can cause bugs,/,22X,23Has you will see in this
     + ,9H example.)
      WRITE (*,20)
   20 FORMAT (9X,49H2) Especially problematic are circumstances such
     2 ,37Has this example with two such formats)
      WRITE (*,*)
      END

The compiler says:

[FTN95/Win32 Ver. 8.63.0 Copyright (c) Silverfrost Ltd 1993-2020]
0009)       WRITE (*,20)
*** Continuation of Hollerith strings is not supported

    1 ERROR [hbug.F] - Compilation failed.

The wording of the error message suggests that the compiler objects to one of the two FORMAT statements rather than the WRITE statement. After trying several changes to the two FORMAT statements, I found that what may be happening is as follows.

Line 10 contains a Hollerith descriptor of stated length 49. That implies that the line should contain a space character at the end of the line before EOL. However, most text editors remove trailing spaces from program source lines, and Fortran compilers pad fixed form source line ends with blanks. FTN95 does not appear to do so, and in most circumstances it would not matter, but not here. It probably finds only 48 characters before EOL, and issues the error message. To test this, I placed a character in column 73 of that line, and that made the error message go away.

8 Jul 2020 7:15 #25932

mecej4

Thank you for the bug report. I have logged as needing attention.

8 Jul 2020 8:36 (Edited: 8 Jul 2020 9:48) #25934

That looks like a hard one to catch - although interesting to see how you set out the demonstrator, as in most old Fortran FORMATs with Holleriths they were written in capitals only. Seeing that in someone else's old code might alert me to an issue with line length (maybe, if I was having a good day).

As a matter of style, I always avoided Holleriths that ran over into a continuation line because I found them difficult to read, and doubly difficult to edit the FORMAT without causing errors. Once, in a moment of forgetfulness, I tried to concatenate two strings in a FORMAT using // as you might somewhere other than there. It doesn't work - for obvious reasons, as // means something else in a FORMAT. I put it down to tiredness.

Incidentally, in helping someone with old code I found that their original compiler had been less fussy about commas in FORMAT statements than FTN95, or probably the Standard (or even than I am).

Good catch.

Eddie

And yes, sometimes these things do sting - again and again.

8 Jul 2020 9:38 #25935

This bug has now been fixed for the next release of FTN95.

Please login to reply.