我想知道以下代码是否合法:
module my_mod
contains
subroutine my_outer_sub(a)
integer, intent(in) :: a
call my_inner_sub()
contains
subroutine my_inner_sub()
a=3 ! this compiles and runs!
end subroutine my_inner_sub
end subroutine my_outer_sub
end module my_mod
我用PGI 17.4编译了代码。我一直在模块子程序中使用包含的子程序,现在我想知道这个方案是否合适?
答案 0 :(得分:1)
不,代码是非法的。您无法修改intent(in)
参数。这是编译器中的错误,应该报告给您的供应商。
Gfortran正确识别
Error: Dummy argument 'a' with INTENT(IN) in variable definition context (assignment) at (1)
英特尔Fortran也是如此
intent3.f90(11): error #6780: A dummy argument with the INTENT(IN) attribute shall not be defined nor become undefined. [A]
a=3 ! this compiles and runs!
------^
compilation aborted for intent3.f90 (code 1)