Fortran Coder

查看: 8090|回复: 8
打印 上一主题 下一主题

[指针] 如何使用函数变量

[复制链接]

237

帖子

0

主题

0

精华

版主

World Analyser

F 币
638 元
贡献
468 点

新人勋章美女勋章元老勋章热心勋章规矩勋章管理勋章

QQ
楼主
发表于 2017-10-25 09:09:43 | 显示全部楼层
可以用 Procedure Pointers 这个东西(中文应该叫 过程指针)

[Fortran] 纯文本查看 复制代码
Module Proc2
  Implicit None
  
  interface
    Subroutine IF_PROC(x,y)
      integer :: x , y
    End Subroutine IF_PROC
  end interface
  
contains

  Subroutine f1(x,y)
    integer :: x , y
    write(*,*) x+y
  End Subroutine f1
  
  Subroutine f2(x,y)
    integer :: x , y
    write(*,*) x-y
  End Subroutine f2
  
End Module Proc2
  
Program Proc_pointer
  use Proc2
  Implicit None
  integer :: x , y , n
  Procedure(IF_PROC) , pointer :: proc
  read(*,*) n , x , y
  if(n==1) then
    proc => f1
  else
    proc => f2
  end if
  call proc(x,y)
End Program Proc_pointer
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-5 11:41

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表