Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28447 Discussions

catching error due to larger adjustable array at run-time

New Contributor I


The test-case below captures the gist of an error; where is the cause that the adjustable array is bigger than what has been passed in. It cannot be caught by the compiler; I understand. I am wondering is there a way (as in a flag) to catch it at run-time. Compiling with ifort /check:all Test.f90 won't do.

As you can imagine this is extracted from rather deep inside a combination of legacy and new program. In one of the test-cases of that program, it revealed itself as "access violation" but that was at a different location. 



      Module OM
         Implicit None
         Integer :: M, N
         Integer :: L
         Subroutine Set()
            M = 3; N = 5
         End Subroutine Set
         Subroutine Tech(K)
            Integer :: K(N) ! Size is larger than what's passed; its incorrect.
            Integer :: L
            K = -1 ! any way to catch this error at run-time?
            L = K(N) - 1 ! or here?
            Write(*,"(2(A,X,I0,X))") "in Tech: K(N) =", K(N), " and L =", L
         End Subroutine Tech
      End Module OM
      Program Test
         Use OM
         Implicit None
         Integer, Allocatable :: I(:)
         Call Set()

         I = 0
         Call Tech(I)
          Write(*,"(A,X,I0,X)") "after the call L =", L
      End Program Test      


0 Kudos
3 Replies
Honored Contributor II

Did you try /check:bounds?

A question: can you not use assumed-shape array argument and if the length is inadequate, do some error handling instead?

subroutine Tech(K)
   ! Argument list
   integer :: K(:) !<-- assumed shape
   if ( size(K) < N ) then
    ! Size is shorter than desired, do the needful


0 Kudos
New Contributor I

Hi FortranFan

Thanks for your comment.

(a) As I mentioned, this doesn't get trapped with /check:all. So, no /check:bounds won't catch it.

(b) Yes, there are ways to rectify this. But since this is coming from some legacy things, I am wondering if it can't be caught. 


0 Kudos
Honored Contributor III

Intel Fortran doesn't offer a check for this sort of thing. It would require passing extra information in a way that would break existing programs.

Better to use assumed-shape arrays.

0 Kudos