pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
int i;
label L1;
int subproc s (x);
int (x);
begin
label L2:
if x = 0 then goto L1; ! Nonlocal goto
if x > 10 goto L2; ! Local goto
return 1;
L2: return x;
end;
i := s (global_var);
if i <> 1 then goto L1; ! Local goto
! Processing occurs here
L1:
end;
GOTO and Target Statements With Different Trapping States
A GOTO statement, local or nonlocal, must have the same trapping state as its target statement.
Example 162 Local GOTO and Target Statements That Have Different Trapping States
proc p nooverflow_traps;
begin
subproc s overflow_traps;
begin
goto L1; ! Illegal trapping states differ
end;
L1:
end;
If a GOTO statement and the target statement are in different BEGIN-END blocks:
• You must declare the target label in a LABEL declaration in the containing procedure.
NOTE: LABEL is an invalid data type for a formal parameter. You cannot pass a label as
an actual parameter.
• Overflow trapping must be enabled in both blocks or disabled in both blocks. The respective
overflow trapping states can be established by compiler directive, by procedure attribute, or
by BEGIN-END block attribute.
• A GOTO statement in a BEGIN-END block that does not specify a block-level trapping attribute
cannot branch to a label in a BEGIN-END block in which a block-level trapping attribute is
specified.
The compiler uses attributes on BEGIN-END blocks to determines whether a GOTO within one
BEGIN-END block can branch to a label in another BEGIN-END block.
For more information, see Chapter 13 (page 234).
Example 163 Nonlocal GOTO and Target Statements That Have Different Trapping States
PROC p OVERFLOW_TRAPS;
BEGIN
INT i := 0;
label_a: ! Overflow traps are enabled at label_a
i := i + 1;
IF i < 10 THEN
GOTO label_a ! OK: Traps enabled here and at label_a
ELSE
BEGIN:ENABLE_OVERFLOW_TRAPS
GOTO label_a; ! OK: Branch from block with traps
216 Statements