fortran goto范围 [英] fortran goto scope

查看:458
本文介绍了fortran goto范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个遗留的Fortran代码,带有许多像'goto 50'这样的语句。我想知道goto的目标是全球还是本地。我的意思是,如果多个函数的目标是'50',那么goto通向哪里。



感谢您的回答。



例如,在下面的程序中,主程序和两个子程序有自己的标签50,并且gotos进入他们的行50。

  program testgotos 
implicit none

转到50
通话第二个
通话第一个
通话第二个

包含

子程序第一个
integer:a = 10

goto 50
a = 20
50 print *,'First:a =',a

结束子程序优先

子程序秒
integer :: a = 20

goto 50
a = 40
50 print *,'Second:a =',a

结束子程序第二个

结束程序testgotos


I have a legacy fortran code with many statements like 'goto 50'. I was wondering whether the target of goto is global or local. I mean, if multiple functions have a target '50', where does the goto leads to.

Thanks for answering.

解决方案

The statement labels (eg, "50") have to be defined within the current "scoping unit", which basically translates in this context to the subroutine/function that the goto call is in (or the main program, if the call is in the main program).

So for instance, in the following program, the main program and both contained subroutines have their own label 50, and the gotos go to "their" line 50.

program testgotos
    implicit none

    goto 50
    call second
 50 call first
    call second

contains

    subroutine first
    integer :: a = 10

    goto 50
    a = 20
 50 print *,'First: a = ', a

    end subroutine first

    subroutine second
    integer :: a = 20

    goto 50
    a = 40
 50 print *,'Second: a = ', a

    end subroutine second

end program testgotos

这篇关于fortran goto范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆