Automatic array allocation in Fortran 95?

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
Messages
2,797
Reaction score
21
The following code seems to run ok under fortran 95 (g95 compiler), but I was unsure about the exact nature of the array assignment. As you can see it is a variable sized array, without any explicit "allocate" command. The code works even when the array size could not be known at compile time, so I'm guessing that it's automatically allocated on the stack at run time. Just wondering if this legitimate Fortran 95 syntax (or something compiler specific)?

Code:
 subroutine test(n)
 integer :: n
 implicit none

   integer :: a(n)     ! Is this automatic allocation?
   integer :: k
   do k=1,n
      a(k)=k
   end do
   print *,a

 end subroutine test
 
Physics news on Phys.org
It's legal, it is called Automatic Object.

...gotta run.