Automatic array allocation in Fortran 95?

  • Fortran
  • Thread starter uart
  • Start date
  • #1
uart
Science Advisor
2,776
9

Main Question or Discussion Point

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
 

Answers and Replies

  • #2
1,065
53
It's legal, it is called Automatic Object.

...gotta run.
 
  • #3
uart
Science Advisor
2,776
9
Thanks gsal :smile:
 

Related Threads for: Automatic array allocation in Fortran 95?

Replies
6
Views
4K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
2
Views
6K
Replies
1
Views
3K
Replies
4
Views
8K
Replies
8
Views
2K
Replies
2
Views
7K
Replies
2
Views
4K
Top