Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Automatic array allocation in Fortran 95?

  1. Sep 28, 2012 #1


    User Avatar
    Science Advisor

    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 (Text):

     subroutine test(n)
     integer :: n
     implicit none

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

     end subroutine test
  2. jcsd
  3. Sep 28, 2012 #2
    It's legal, it is called Automatic Object.

    ...gotta run.
  4. Sep 28, 2012 #3


    User Avatar
    Science Advisor

    Thanks gsal :smile:
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook