pTAL Conversion Guide

Statements
pTAL Conversion Guide527302-002
15-15
Overflow Traps in pTAL
Overflow Traps in pTAL
In pTAL, if a GOTO statement and the target of the GOTO statement are in different
BEGIN-END blocks:
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 determines whether a GOTO in one BEGIN-END block can branch to
a label in another BEGIN-END block only by the attributes on the BEGIN-END
blocks or on encompassing BEGIN-END blocks, not by the presence or absence of
an overflow trapping compiler directive or procedure attribute.
Example 15-20. Overflow Traps and GOTO Statements
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 specified
IF i <> 1 THEN
BEGIN
label_b: ...
END;
END;
BEGIN:DISABLE_OVERFLOW_TRAPS
GOTO label_b; ! ERROR: cannot branch between blocks
END; ! that have different trapping states
BEGIN
GOTO label_b; ! ERROR: cannot branch from a BEGIN-END
END; ! block that does not specify a trapping
END; ! attribute to a BEGIN-END block that does