(j3.2006) GOTO label - with label in BLOCK and in inclusive scope
Bill Long
longb
Thu Aug 18 12:23:52 EDT 2011
On 8/18/11 7:35 AM, Tobias Burnus wrote:
> Dear all,
>
> I was wondering whether the following program is valid - and, if so, to
> which label jumps the goto?
>
> block
> goto 1
> stop "one"
> 1 continue
> stop "two"
> end block
> 1 continue
> stop "three"
> end
>
The code compiles for me and executes as
> ./a.out
STOP two
which indicates that the "local" label 1 wins as the target of the goto.
But it sure LOOKS confusing in a small program like this. All sorts
of obfuscated Fortran opportunities come to mind... On the other hand,
the point of BLOCK constructs is to write code with localized variables
that is non-disruptive to the surrounding environment. In a larger
code, the ability to have non-colliding statement labels would be valuable.
Cheers,
Bill
>
> The programs seems to be valid as the following is fulfilled:
>
> "The same statement label shall not be given to more than one statement
> in its scope." (F2008, "3.2.5 Statement labels")
>
> And BLOCK is a scoping unit of its own: "1.3.124 scoping unit. BLOCK
> construct, derived-type definition, interface body, program unit, or
> subprogram, excluding all nested scoping units in it."
>
> And "8.2 Branching" tells me:
> "A branch causes a transfer of control from one statement to a labeled
> branch target statement in the same inclusive scope."
>
> Plus for GOTO (R851):
> "C846 (R851) The label shall be the statement label of a branch target
> statement that appears in the same inclusive scope as the goto-stmt."
>
> with
>
> "1.3.87 inclusive scope. nonblock scoping unit plus every block
> scoping unit whose host is that scoping unit or that is nested within
> such a block scoping unit
> NOTE 1.5
> That is, inclusive scope is the scope as if BLOCK constructs were not
> scoping units."
>
>
> Thus, also the GOTO seems to be valid. However, to which label does the
> GOTO jump to?
>
> Tobias
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3
--
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
More information about the J3
mailing list