Silverfrost Forums

Welcome to our forums

FTN95 gets scope of interface definition wrong

9 Feb 2018 5:33 #21373

This is a bug report about FTN95 8.10, 32- and 64-bit.

Given the interface definition (file fnint.f90)

    module fn_int
       interface
          subroutine f(x, v)
             real, dimension (:), intent (in) :: x
             real, dimension (:), intent (out) :: v
          end subroutine f
       end interface
    end module fn_int

and a subroutine that uses that interface (file stpqf.f90):

    subroutine stpqf(n, y, a, f0)
       use fn_int
       implicit none
       integer :: n
       real :: a(n), f0(n+1), y(n)
!
       call f(y(2:n+1), f0(1:n))
       f0(1:n) = y(1)*f0(1:n) + (1.0-y(1))*(y(2:n+1)-a(1:n))
       return
!
    end subroutine stpqf

the compiler has no problems. Likewise, it handles the following (file stpds.f90):

    subroutine stpds(f, neqn, y, x, yp)
       implicit none
       real :: x
       integer :: neqn
!
       real :: y(neqn), yp(neqn)
!
       interface
          subroutine f(s, y, yp, n)
             integer :: n
             real :: s, y(n+1), yp(n+1)
          end subroutine f
       end interface

       call f(x, y, yp, neqn-1)
       return
    end subroutine stpds

However, if the subroutines occur in the same source file, with the code for STPDS preceding that for STPQF, the compiler gives an incorrect error message. For the source file stp.f90, with contents:

include 'stpds.f90'
include 'stpqf.f90'

the compiler says:

1/0007)        call f(y(2:n+1), f0(1:n))
*** The third argument (YP) to F is missing (In include file s:\Homp\splt\stpqf.f90)
*** The fourth argument (N) to F is missing

The F with 4 arguments is a dummy argument to STPDS, and its actual name/address is not known at compile time. The subroutine with the actual name F takes 2 arguments and is called from STPQF. Within STPQF, the interface to the 4 argument subroutine F is not in scope.

NOTE: The actual code that caused me to notice this bug is HOMPACK90.F at http://people.cs.vt.edu/~ltw/hompack/hompack90/ . The code above resulted from ruthless deletion of lines from that source file.

10 Feb 2018 9:46 #21378

mecej4

Many thanks for the feedback and for the effort you have made to reduce this to a short piece of coding.

FTN95 remembers some things between separate program units when they occur in the same file and this is not always appropriate.

18 Jul 2019 5:37 #24029

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

Please login to reply.