Click here to Skip to main content
15,867,308 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralClassic FORTRAN Pin
trønderen30-Dec-22 5:28
trønderen30-Dec-22 5:28 
GeneralRe: Classic FORTRAN Pin
Graeme_Grant30-Dec-22 6:32
mvaGraeme_Grant30-Dec-22 6:32 
GeneralRe: Classic FORTRAN Pin
Craig Robbins30-Dec-22 7:21
Craig Robbins30-Dec-22 7:21 
GeneralRe: Classic FORTRAN Pin
Slacker00730-Dec-22 7:36
professionalSlacker00730-Dec-22 7:36 
GeneralRe: Classic FORTRAN Pin
trønderen30-Dec-22 9:18
trønderen30-Dec-22 9:18 
GeneralRe: Classic FORTRAN Pin
haughtonomous2-Jan-23 21:56
haughtonomous2-Jan-23 21:56 
GeneralRe: Classic FORTRAN Pin
lewist573-Jan-23 8:43
lewist573-Jan-23 8:43 
GeneralRe: Classic FORTRAN Pin
trønderen3-Jan-23 9:21
trønderen3-Jan-23 9:21 
Spaces are completely ignored in F77 (and earlier). Columns are significant - specifically col 6. This would be another valid version of the program:
.     PROGRAMPROGRAM
      INTEGERIF,INTEGER,GOTO,IMPLICIT
      REALREAL,DIMENSION,EXTERNAL,FORMAT,END
      INTEGERLOGICAL
      REALCOMPLEX,DATA,CALL,ASSIGN,CHARACTER
      DOFORIF=INTEGER,INTEGER;ENDDO
      INTEGER=IF+IF
      GOTO=INTEGER*INTEGER*INTEGER*INTEGER-INTEGER-IF
      CALLFUNCTION(IMPLICIT,REAL,DIMENSION,EXTERNAL,FORMAT,END
     $,LOGICAL,COMPLEX,DATA,CALL,ASSIGN,CHARACTER)
      CALLSUBROUTINE(IMPLICIT, LOGICAL, GOTO, IF, INTEGER)
      END
      SUBROUTINEFUNCTION(IMPLICIT,REAL,DIMENSION,EXTERNAL,FORMAT
     $,END,LOGICAL,COMPLEX,DATA,CALL,ASSIGN,CHARACTER)
      RETURN
      END
      SUBROUTINESUBROUTINE(IMPLICIT,LOGICAL,GOTO,IF,INTEGER)
      INTEGERGOTO,IMPLICIT(GOTO),LOGICAL(GOTO),IF,INTEGER
     $,EXTERNAL,RETURN
      DOFOREXTERNAL=IF,GOTO
      DOFORRETURN=EXTERNAL,EXTERNAL-IF
      IMPLICIT(RETURN)=LOGICAL(RETURN)+LOGICAL(RETURN-IF)
      ENDDO
      IMPLICIT(IF)=IF
      IMPLICIT(EXTERNAL)=IF
      DOFORRETURN=IF,GOTO-EXTERNAL
      WRITE(IF,'(''$ '')')
      ENDDO
      DOFORRETURN=IF,EXTERNAL
      WRITE(IF,'(''$''I4)')IMPLICIT(RETURN)
      ENDDO
      WRITE(IF,'( /)')
      DOFORRETURN=IF,GOTO
      LOGICAL(RETURN)=IMPLICIT(RETURN)
      ENDDO
      ENDDO
      END
This is (printable) character by character identical to the first version I presented. I am not 100% sure that F77 allows semicolon to put multiple statements on one line; there is one case of it in the above code, and both the F77 compilers we had access to accepted it. I could have filled up the lines to col.72 to make the code even more compact Smile | :) , but I'll leave that as an exercise for those with extreme tastes in code layout ...
lewist57 wrote:
2) no DATA statements or other initialization of the varables?
We had denied ourselves the use of literals (but had to lift those restrictions for the strings in the WRITE statements).

However: F77 specifies that integer values are initialized to zero. Fortran loops are always executed at least once. So INTEGER starts at 0, and when running
DO FOR IF = INTEGER, INTEGER; ENDDO
the loop will increment INTEGER from 0 to 1. Then we create 2 by adding IF + IF, and 13 by INTEGER*INTEGER*INTEGER*INTEGER-INTEGER-IF (i.e. 2*2*2*2 - 2 - 1).

In principle, we could have created ASCII character codes for the string constants in a COMMMON block, and addressed the block alternately as integer or string. That would require knowledge about how a string is laid out in memory, and the code would have to be split in two files (one file can only interpret the common block in a single way). I believe that Hollerith constants are defined to be a plain octet sequence in memory - no descriptor, no terminator - but Hollerith was left out of F77 (and all later versions), wasn't it?

Today, I have forgotten why we have this no-op subroutine named FUNCTION. It could be for some other strange initialization purpose. All I remember is that it had to be there. If I dig up an F77 compiler and debugger, maybe I could tell. My life does not depend on knowing the answer, so I doubt that I will acquire and install an F77 for the sole purpose of finding out Smile | :)
GeneralRe: Classic FORTRAN Pin
lewist573-Jan-23 9:49
lewist573-Jan-23 9:49 
GeneralRe: Classic FORTRAN Pin
jsc423-Jan-23 10:53
professionaljsc423-Jan-23 10:53 
GeneralRe: Classic FORTRAN Pin
Peter_in_27803-Jan-23 11:07
professionalPeter_in_27803-Jan-23 11:07 
GeneralRe: Classic FORTRAN Pin
jsc423-Jan-23 23:25
professionaljsc423-Jan-23 23:25 
GeneralRe: Classic FORTRAN Pin
trønderen3-Jan-23 16:54
trønderen3-Jan-23 16:54 
GeneralRe: Classic FORTRAN Pin
lewist574-Jan-23 5:27
lewist574-Jan-23 5:27 
GeneralRe: Classic FORTRAN Pin
trønderen4-Jan-23 8:53
trønderen4-Jan-23 8:53 
GeneralRe: Classic FORTRAN Pin
lewist576-Jan-23 16:02
lewist576-Jan-23 16:02 
GeneralLong filename problems in 2022? Pin
honey the codewitch24-Oct-22 14:40
mvahoney the codewitch24-Oct-22 14:40 
GeneralRe: Long filename problems in 2022? Pin
MarkTJohnson25-Oct-22 7:21
professionalMarkTJohnson25-Oct-22 7:21 
GeneralRe: Long filename problems in 2022? Pin
honey the codewitch25-Oct-22 8:22
mvahoney the codewitch25-Oct-22 8:22 
GeneralRe: Long filename problems in 2022? Pin
Jörgen Andersson25-Oct-22 21:28
professionalJörgen Andersson25-Oct-22 21:28 
GeneralRe: Long filename problems in 2022? Pin
honey the codewitch26-Oct-22 0:43
mvahoney the codewitch26-Oct-22 0:43 
GeneralRe: Long filename problems in 2022? Pin
Nelek4-Nov-22 15:28
protectorNelek4-Nov-22 15:28 
GeneralRe: Long filename problems in 2022? Pin
honey the codewitch4-Nov-22 15:49
mvahoney the codewitch4-Nov-22 15:49 
GeneralRe: Long filename problems in 2022? Pin
Nelek5-Nov-22 10:26
protectorNelek5-Nov-22 10:26 
GeneralRe: Long filename problems in 2022? Pin
Gary R. Wheeler10-Dec-22 6:33
Gary R. Wheeler10-Dec-22 6:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.