Re: allocation error



"lane straatman" <grumpy196884@xxxxxxxxxxx> wrote in message
news:1167413501.898092.150810@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

program pascal1
IMPLICIT NONE
integer :: n, i
integer, dimension(:), allocatable :: pascal
allocate(pascal(1:n))
write (*,'(a)', advance='no') 'give me an int'
read (*, '(i3)') n
do i=1, n
pascal(n) = i
write (*, '(i3)') pascal(i)
end do
end program pascal1
This program wants to dynamically allocate an array of rank 1. It
compiles and builds but has the following bug:

It isn't a bug. It's a programming error.
The value of N needs to be read in before
executing the ALLOCATE statement.

Run-time Error
*** Error 112, Reference to undefined variable, array element or

It's describing what the error is -
an undefined variable, viz., N.


.



Relevant Pages

  • allocation error
    ... end program pascal1 ... This program wants to dynamically allocate an array of rank 1. ... Run-time Error ... *** Error 112, Reference to undefined variable, array element or ...
    (comp.lang.fortran)
  • Re: allocation error
    ... That's because your allocate is before you read the value of n. ... is an executable statement. ... end program pascal1 ... get fortran output to look proper, but that was a different century.) ...
    (comp.lang.fortran)