Re: allocation error
- From: "Beliavsky" <beliavsky@xxxxxxx>
- Date: 29 Dec 2006 11:01:18 -0800
dpb wrote:
Richard Maine wrote:
lane straatman <grumpy196884@xxxxxxxxxxx> wrote:
allocate(pascal(1:n))...
write (*,'(a)', advance='no') 'give me an int'
read (*, '(i3)') n
*** Error 112, Reference to undefined variable, array element or
function result (/UNDEF)
That's because your allocate is before you read the value of n. Allocate
is an executable statement. It does its thing when it is executed, which
in this case is before n is defined. My guess is that you are thinking
it does something more complicated like make the array size track the
value of n as n changes. Nope, it is much simpler than that.
Question, Richard--would the use of a STAT variable if it had been used
(and subsequently tested, of course) been required to catch this
particular error? Or is the undefined status of n a non-required error
to be caught?
The following does not directly answer your question.
I have made the OP's error of allocating an array to a size specified
by a variable that has not been set. What typically happens is that "n"
is randomly set to some very large value, causing the ALLOCATE to fail
and the program to crash (I don't use a STAT with the ALLOCATE). For me
this works well, since I quickly notice the bug and fix it.
.
- Follow-Ups:
- Re: allocation error
- From: dpb
- Re: allocation error
- References:
- allocation error
- From: lane straatman
- Re: allocation error
- From: Richard Maine
- Re: allocation error
- From: dpb
- allocation error
- Prev by Date: Re: allocation error
- Next by Date: Re: allocation error
- Previous by thread: Re: allocation error
- Next by thread: Re: allocation error
- Index(es):
Relevant Pages
|