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

Assumed arrays

Mathieu_D_
Beginner
453 Views

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
  contains

    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(:)

  allocate(d(1))
  d = 0
  call sub(d)

end program

0 Kudos
2 Replies
mecej4
Honored Contributor III
453 Views

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:

[bash]

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[/bash]

0 Kudos
Steven_L_Intel1
Employee
453 Views

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).

0 Kudos
Reply