"intent" 是否保证模块包含的子例程内包含的子例程?

Is "intent" guaranteed for contained subroutines inside a module contained subroutine?

我想知道下面的代码是否合法:

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 编译了代码。我一直在模块子程序中使用包含的子程序,现在我想知道这个方案是否合适?

不,代码不合法​​。您不能修改 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)