Assumed arrays

Assumed arrays

The following obviously wrong program can be compiled with intel fortran compiler 13.1.3 with no error.

What compile option would detect it at compile time or run time ? We tried -check all and -warn interfaces,nouncalled -fpp -gen-interface -g -traceback -check uninit -check bounds -check pointers with no success. On the good side, valgrind detects the error. But valgrind also find many false problems with fortran programs.

module moduleA

    subroutine sub(d)
      implicit none
      integer, intent(inout) :: d(10)

      d = 100
    end subroutine

end module

program testprogram
  use moduleA
  implicit none

  integer, allocatable :: d(:)

  d = 0
  call sub(d)

end program

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The explicit declaration of a dummy array with an incorrect subscript range is likely to hobble the compiler's error checking capabilities. You may try after replacing "d(10)" by "d(*)". 

Compilers from different vendors vary in their error-trapping capabilities. The NAG compiler gives, for your program, the following run time error:

Runtime Error: dufour.f90, line 4: Invalid reference to procedure MODULEA:SUB - Dummy arra
y D (number 1) has 10 elements but actual argument only has 1 elements

In the case of an explicit-shape array dummy argument, we don't pass any bounds information. If the compiler can see the bounds of both arrays, it can complain, but in this case the bounds of the passed array are not known until run-time. There are some compilers that pass extra bounds information but this can cause calling compatibility issues.

We do catch the more common case of passing an array declared, say, (2) to one declared (10).

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today