【问题标题】:Is "intent" guaranteed for contained subroutines inside a module contained subroutine?模块包含的子例程中包含的子例程是否保证“意图”?
【发布时间】:2018-01-09 17:13:20
【问题描述】:

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

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

【问题讨论】:

    标签: module fortran contains subroutine


    【解决方案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)
    

    【讨论】:

    • 谢谢。我修改了问题,我的意思是如果编译中没有错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 1970-01-01
    • 2014-03-18
    • 2017-02-25
    • 2020-06-30
    相关资源
    最近更新 更多