intent(out) and allocatable Fortran arrays: what is really done?

Ste*_*611 3 fortran allocatable-array

I read on many posts on Stack Overflow that an allocatable array is deallocated when it is passed in a subroutine where the dummy argument is intent(out).

If I consider the following code :

program main

 real, dimension(:), allocatable :: myArray
 integer :: L=8

 allocate(myArray(1:L))
 call initArray(myArray)
 print *, myArray
 
contains

 subroutine initArray(myArray)
 real, dimension(:), intent(out) :: myArray

 myArray(:) = 10.0
 
 end subroutine initArray
 
end program main
Run Code Online (Sandbox Code Playgroud)

输出是正确的。因此,当发生释放时,内存被释放,但数组形状保持不变。准确吗?任何详细的解释将不胜感激。

我阅读了有关该主题的不同帖子(我可以在 Fortran 中使用可分配数组作为意图(输出)矩阵吗?将可分配变量传递到具有不可分配参数的子例程的效果是什么?,...)。所以我知道数组已被释放,但我想了解这是什么意思,因为在我的代码中,大小被保留,而且我也对这段代码的工作原理感到惊讶。

fra*_*lus 6

您稍微误解了这里发生的情况。

在进入过程时释放的数组intent(out)是与可分配虚拟对象相对应的可分配数组。

论证的意义完全取决于虚拟论证intent(out)的特征,而不是实际论证。

与普通虚拟参数相对应的可分配实际参数不会被释放。(如果是,则必须不分配不可分配的虚拟参数!)

相反,实际参数的分配状态保持不变,并且假定(非延迟)形状虚拟参数的形状保持不变。

虚拟参数变得未定义,作为intent(out). 对于这里的普通虚拟参数,它仅指它的值(在该赋值语句中立即定义)。