Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fortran goto scope

Tags:

fortran

goto

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.

like image 461
user984260 Avatar asked Dec 09 '22 01:12

user984260


2 Answers

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
like image 121
Jonathan Dursi Avatar answered Dec 27 '22 07:12

Jonathan Dursi


Local.

Technically from the f77 standard ( http://www.fortran.com/fortran/F77_std/f77_std.html )

"Statement labels have a scope of a program unit."

like image 42
Brian Swift Avatar answered Dec 27 '22 08:12

Brian Swift