Automatic array allocation in Fortran 95?

  • Fortran
  • Thread starter uart
  • Start date
  • #1
uart
Science Advisor
2,797
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
 

Answers and Replies

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

...gotta run.
 
  • #3
uart
Science Advisor
2,797
21
Thanks gsal :smile:
 

Suggested for: Automatic array allocation in Fortran 95?

  • Last Post
Replies
12
Views
533
  • Last Post
Replies
4
Views
562
  • Last Post
Replies
20
Views
2K
Replies
32
Views
1K
  • Last Post
Replies
16
Views
2K
  • Last Post
Replies
8
Views
544
Replies
5
Views
780
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
6
Views
427
Replies
1
Views
505
Top