FORTRAN - 子程序中的可分配数组 [英] FORTRAN - allocatable array in subroutine
问题描述
我正在尝试在子例程中使用可分配数组,但编译器抱怨
I'm trying to use an allocatable array in a subroutine but the compiler complains that
Error: Dummy argument 'locs' with INTENT(IN) in variable definition context (ALLOCATE object) at (1)
我唯一能找到的是我应该使用显式接口,我正在这样做.这里是子程序的相关代码:
The only thing I could find was that I am supposed to use an explicit interface, which I am doing. Here the relevant code for the subroutine:
RECURSIVE SUBROUTINE together(locs, LL, RL)
INTEGER, DIMENSION(:,:), ALLOCATABLE, INTENT(IN) :: locs
INTEGER, INTENT(IN) :: LL, RL
ALLOCATE(locs(LL,RL))
END SUBROUTINE together
推荐答案
编译器的错误信息是对问题的一种描述.使用 INTENT(IN)
你是说对象不会改变,但是你继续尝试 ALLOCATE
它.
The compiler's error message is one descriptive of the problem. With INTENT(IN)
you are saying that the object will not change, but you then go on to attempt to ALLOCATE
it.
是的,调用需要显式接口,但这不是问题.
Yes, an explicit interface will be required for the calling, but that isn't the problem.
Fortran 2008 标准在第 5.3.10 节中指出
The Fortran 2008 standard says in section 5.3.10 that
具有 INTENT (IN) 属性的非指针对象不应出现在变量定义上下文中
A nonpointer object with the INTENT (IN) attribute shall not appear in a variable denition context
分配就是这样一种上下文:第 16.6.7 节,第 (11) 点.
Allocation is one such context: section 16.6.7, point (11).
这篇关于FORTRAN - 子程序中的可分配数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!