Detecting uninitialized subroutine argument used as array bound of another argument
- From: mecej4 <mecej4@xxxxxxxxxxxxx>
- Date: Mon, 29 Oct 2007 08:48:16 -0500
The short program below is a digest of an error in a much more complex and
larger program:
1 program test
2 implicit none
3 integer ia,nmax
4 dimension ia(10)
5 c
6 c Suppose the next line is left out by mistake
7 c nmax = 10
8 c
9 call sub(ia,nmax)
10 end
11 subroutine sub(ia,nmax)
12 implicit none
13 integer nmax,ia(nmax),i
14 do i=1,10
15 ia(i)=i
16 end do
17 return
18 end
The bug is the commented out Line-7. There are features in the algorithm of
the large program which necessitate using an upper limit other than 'nmax'
for the DO loop on Line-14.
My question is not about how to fix the bug, but as to what one may expect
from a compiler that provides facilities for subscript checking and, even
better, with facilities for trapping usage of uninitialized variables.
Here are the outputs from a number of different compilers. Which, in your
opinion, is the most helpful message?
-- mecej4
___________________________________________________________
1.
Reference to undefined variable NMAX
Program terminated by fatal error
In SUB, line 11 of tst.f
Called by TEST, line 9 of tst.f
Aborted
2.
Subscript out of range for array ia (subscript: 1, declared size: 0).
Error occurs at or near line 15 of sub_
Called from or near line 9 of MAIN__
3.
****** FORTRAN RUN-TIME SYSTEM ******
Subscript out of range. Location: line 15 column 13 of 'tst.f'
Subscript number 1 has value 1 in array 'IA'
Aborted
4.
At line 15 of file tst.f
Traceback: (Innermost first)
Called from line 9 of file tst.f
Fortran runtime error: Array element out of bounds: 1 in (1:0), dim=1
5.
forrtl: severe (408): fort: (2): Subscript #1 of the array IA has value 1
which is greater than the upper bound of -858993460
.
- Follow-Ups:
- Prev by Date: Re: detect Inf or NaN
- Next by Date: Re: Doubts about appending data to a file
- Previous by thread: Winteracter
- Next by thread: Re: Detecting uninitialized subroutine argument used as array bound of another argument
- Index(es):
Relevant Pages
|
|