Re: allocation error



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.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.



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: jtable add row
    ... >the constuctor is like this: ... >class MyTableModel extends AbstractTableModel { ... You don't need to allocate new ... just copy over a reference to each row. ...
    (comp.lang.java.programmer)
  • Re: Halt execution procedure
    ... actually spend the time to check on that, but the general model of allocate on entry, deallocate on exit doesn't work very cleanly for common. ... The compiler is free to implement, say, reference counting on a named COMMON, to allocate it when it first comes into scope and to release its memory when the reference count goes to 0. ...
    (comp.lang.fortran)