Re: allocation error




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.

.



Relevant Pages

  • Re: allocation error
    ... That's because your allocate is before you read the value of n. ... Richard--would the use of a STAT variable if it had been used ... error for *ANY* reference of n while it is undefined. ... to catch some uses of undefined variables. ...
    (comp.lang.fortran)
  • Re: STAT= variable with ALLOCATE
    ... is hard to definitively say that it unambiguously violates the standard. ... about the allocated variable if the STAT value is zero? ... you reference an element that is too large (or reference elements in too ... What other exceptional conditions, beyond lack of resources, can predispose a compiler not to allocate the requested memory? ...
    (comp.lang.fortran)
  • Re: How java passes object references?
    ... to think of them as being a specific location in a larger block of memory ... Whether a language passes by reference or by value, ... is a pointer pointing at the memory block. ... So when allocating local memory for o, it would simply allocate a ...
    (comp.lang.java.programmer)
  • Re: Detecting return to the desktop after an F12
    ... WimpMonitor application shows only TaskClosedown, PaletteChange, ... Task Manager received message Message_TaskClosedown from Allocate ... with reference &9E8 in reply to message with reference &0 ... task 'Allocate' now has a 252 Kbytes wimpslot ...
    (comp.sys.acorn.programmer)
  • [PATCH 1/6] tracing/function-profiler: do not free per cpu variable stat
    ... The per cpu variable stat is freeded if we fail to allocate a name ... prevent possible memory corruption on low mem at boot up] ... we still do not free memory. ...
    (Linux-Kernel)