Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran 90 Differences in declaring allocatable array

Is there a difference between

integer, intent(in) :: n
integer, dimension(:), allocatable :: a
allocate(a(n))

and

integer, intent(in) :: n
integer, dimension(n) :: a

In which situation would we use the first version? Perhaps I misunderstood allocatable array, is the second version even an allocatable array?

like image 349
Fabricator Avatar asked Jun 21 '14 02:06

Fabricator


1 Answers

The second case indeed doesn't have a allocatable. It is, however, an automatic object.

Ignoring the practical differences in memory use at the implementation level, there is a big difference. Yes, each a is (assuming things not explicitly stated in the question) a local variable which is, after the allocate and the automatic creation, of size n, but in the first case it is allocatable. It can be deallocated, reallocated (perhaps to a different size), and deallocated again. And so on.

The automatic object (second case) cannot be.

like image 158
francescalus Avatar answered Oct 11 '22 14:10

francescalus