Detecting uninitialized subroutine argument used as array bound of another argument



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

.



Relevant Pages

  • RE: Passing an array as argument for custom Function
    ... the array. ... End Sub ... Function zzzAs Variant) ... but when I try to use myarr, I get a "Subscript out of ...
    (microsoft.public.excel.programming)
  • Re: Cobol Myth Busters
    ... Correct interpretation of findings: ... one wonders why you constructed for your testing an array ... How could INDEXED BY speed up a subscript? ... drawn *only* by comparing executions speeds against arrays defined identically ...
    (comp.lang.cobol)
  • Re: Question about 2D VB arrays
    ... "So if you want to have the same memory layout in both languages, ... more inefficient when accessing the array. ... In C++ you would allocate and populate the array in the using ... subscript is Rows and which one is Columns. ...
    (microsoft.public.vb.general.discussion)
  • Re: Allowing zero-dimensional subscripts
    ... The items of a tuple are arbitrary Python objects. ... items are formed by comma-separated lists of expressions. ... the grammar rule used for list subscript is different from the ... an array with n-dimensions of length 3 would have ...
    (comp.lang.python)
  • Re: Allowing zero-dimensional subscripts
    ... items are formed by comma-separated lists of expressions. ... So there's a regular way to create non-empty tuples, and a subscript ... But note neither testlist nor subscriptlist can create an empty tuple. ... an array with n-dimensions of length 3 would have ...
    (comp.lang.python)