根据Fortran标准:
对于非指针虚参,INTENT (OUT)属性指定该虚参在调用过程中变为未定义
然而,这段简单的代码却输出了5
,因此似乎在开始执行该过程(在本例中为子例程)时,该实参并没有变为未定义状态。
subroutine useless(a)
integer, intent(out) :: a
print *,a
end subroutine useless
program test
integer :: n=5
call useless(n)
end program test
我错在哪里了?intent(inout)
和intent(out)
似乎是一样的。
一个具有显式INTENT(OUT)声明的虚拟参数没有给出显式值
。 - Raul Laasner