Re: allocation error
- From: "dpb" <dpbozarth@xxxxxxxx>
- Date: 29 Dec 2006 13:58:06 -0800
Richard Maine wrote:
dpb <dpbozarth@xxxxxxxx> 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?
It has nothing to do with the allocation. Not only is it not required to
be caught, I'd be quite surprised if stat= did much useful for it. The
error is that the undefined variable n is referenced. This would be an
error for *ANY* reference of n while it is undefined.
Some compilers, evidently including the one used by the OP, have options
to catch some (even many) uses of undefined variables. It is certainly
not required by the standard, and I seriously doubt that there exists
any compiler that will catch absolutely every case (though some do
darned well). The code is just illegal and falls in the "anything can
happen" category.
But again, this has nothing in particular to do with stat=. You might
get an error from stat= if the reference to an undefined variable was
not caught, and it appeared to have a negative value or one larger than
could be allocated. But that would just be happenstance - it doesn't
directly constitute detecting the actual error.
Yes, thanks for pointing out the obvious, Richad. I should have taken
the "undefined variable" error message at face value... :)
I always liked the cross-reference listing of the CDC compilers for
giving the defined and referenced line listing for each variable.
Wasn't foolproof, of course, w/ COMMON, etc., but was most helpful in
helping to ensure "define before use" other than by run-time errors.
.
- Follow-Ups:
- Re: allocation error
- From: Terence
- Re: allocation error
- References:
- allocation error
- From: lane straatman
- Re: allocation error
- From: Richard Maine
- Re: allocation error
- From: dpb
- Re: allocation error
- From: Richard Maine
- allocation error
- Prev by Date: Re: OT: Disappointed with Intel and Polyhedron
- Next by Date: Re: OT: Disappointed with Intel and Polyhedron
- Previous by thread: Re: allocation error
- Next by thread: Re: allocation error
- Index(es):
Relevant Pages
|