- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page