Pointers Fortran:指向父模块中的子例程的指针过程

Pointers Fortran:指向父模块中的子例程的指针过程,pointers,fortran,Pointers,Fortran,我在一个孩子模块中偶然发现了一个父亲的程序。我的意思是,这个技巧允许我以上游的方式运行一个进程,与模块的依赖关系树相关。具体来说,以下是一个例子: module parent procedure(likefoo),pointer :: to_foo interface subroutine likefoo end subroutine likefoo end interface contains subroutine run call to_foo e

我在一个孩子模块中偶然发现了一个父亲的程序。我的意思是,这个技巧允许我以上游的方式运行一个进程,与模块的依赖关系树相关。具体来说,以下是一个例子:

module parent
  procedure(likefoo),pointer :: to_foo
  interface 
    subroutine likefoo
    end subroutine likefoo
  end interface
contains
  subroutine run
   call to_foo
  end subroutine
end module 

module child
  use parent
contains
  subroutine foo
      print *, 'hola'
  end subroutine foo
end module 

program main
  use parent
  use child

  to_foo => foo
  call run

end program 
本例通过ifort 13.0.0进行了阳性检测。 我想知道,这段代码是标准所允许的,还是仅仅因为它运行正常,因为它是一个编译器依赖特性?。
感谢您的帮助。

方法很好(使用F2003功能),但要让界面更抽象。对模块依赖的有向图的要求是与这些模块中对过程的调用嵌套正交的概念。

谢谢!,你能再解释一下这两个概念吗?谢谢,againIt意味着您没有真正在子模块中运行过程。主程序的作用域中既有
模块,也有
模块,因此可以将过程指针分配给任何与其接口匹配的可访问过程,在本例中包括
foo
。实际上,不需要使用子模块中的
use parent
。还请注意,虽然这将进行编译,但调用
run
时,
to_foo
可能没有关联,从而产生segfault。您可以使用
关联(to\u foo)
检查此状态。