【发布时间】:2015-04-20 00:06:42
【问题描述】:
根据 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)是一样的。
【问题讨论】:
-
有趣的是,gfortran 和 ifort 都打印 5,尽管 ifort 警告说
A dummy argument with an explicit INTENT(OUT) declaration is not given an explicit value。 -
@Ross 你可能对重新标记是正确的,但是那里有很多类似的问题......如果你想做很多这样的编辑,最好等到你可以编辑而不审查。我经常把fortran90留在那里,即使添加通用标签以确保不会改变OP的意图。
标签: fortran