良好的惯例规定,Fortran中的子程序参数应该每个都有一个指定的意图(即使用 intent(in)
、intent(out)
或 intent(inout)
,详见此问题):
subroutine bar (a, b)
real, intent(in) :: a
real, intent(inout) :: b
b = b + a
...
然而,不指定意图也是合法的Fortran:
subroutine bar (a, b)
real, intent(in) :: a
real :: b
b = b + a
...
除了编译时检查,指定为 intent(inout)
的参数和未指定 intent 的参数之间是否有任何真正的区别?如果我要给老的、没有指定 intent 的代码添加意图,是否需要担心什么?