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.
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
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."