fortran goto范围

use*_*260 4 fortran goto

我有一个遗留的fortran代码,有许多语句,如'goto 50'.我想知道goto的目标是全球还是本地.我的意思是,如果多个函数的目标为'50',那么goto会导致什么.

谢谢回答.

Jon*_*rsi 8

语句标签(例如,"50")必须在当前"范围单元"中定义,该范围基本上在此上下文中转换为goto调用所在的子例程/函数(或主程序,如果调用在主程序).

因此,例如,在下面的程序中,主程序和两个包含的子程序都有自己的标签50,并且gotos转到"他们的"第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
Run Code Online (Sandbox Code Playgroud)


Bri*_*ift 6

本地.

技术上来自f77标准(http://www.fortran.com/fortran/F77_std/f77_std.html)

"声明标签具有程序单元的范围."