Wednesday, September 08, 2021

Abusing FORTRAN

I've been having fun with Microsoft FORTRAN-80 and Nevada FORTRAN on my Kaypro 4/83.

When I was in college, we did a class on FORTRAN abuse - mainly using some design decisions in FORTRAN that cause interesting things to happen.

Consider this code:

c bad program
      integer i
      i=3+5
      write(1,5) i
      call xxx(5)
      i=3+5
      write(1,5) i
    5 format(1x,i4)
      end

      subroutine xxx(n)
      integer n
      n=3
      return
      end

Under Nevada FORTRAN, this prints:

8

6

Why?  Because "5" was passed in to xxx by reference, which was changed to have a value 3.  Yes, under FORTRAN, I could change a constant.

Under Microsoft FORTRAN-80, this did not happen.  Both values stayed at 8.