Previous Topic Next topic Print topic


Label Data

A label prefix on a statement, other than a PROCEDURE or FORMAT statement, is a declaration of a statement label.

The LABEL attribute can be used to declare variables and functions whose values are labels. For example:

A: PROCEDURE; 
   DECLARE L LABEL;
      .
      .
      .
   L1:
      .
      .
      .
   L = L1;

In this example, the label variable L is assigned a statement label value. A subsequent GOTO L; would transfer control to the statement labeled L1.

A label value is a descriptor that consists of two parts. One part designates a statement (the instructions compiled for the statement) and the other part designates a stack frame of the block that immediately contains the statement. In the previous example, the assignment of L1 to L assigns a designator to the statement labeled L1 as part one of L, and assigns a designator to the current stack frame of procedure A as part two of L. The execution of a subsequent GOTO statement uses the stack frame designator only if the GOTO statement is executed in a block activation other than that indicated by the label value. For example:

A: PROCEDURE; 
   DECLARE L LABEL;
      .
      .
      .
   L1:
      .
      .
      .
   L = L1; 
      .
      .
      .
   GOTO L; 
      .
      .
      .
   B: PROCEDURE;
      .
      .
      .
      GOTO L;
           .
           .
           .

In this example, execution of the first GOTO statement simply transfers control to L1 because it occurs within the same block activation in which L1 was assigned to L (and consequently, the stack frame component of L designates the stack frame that is current when the GOTO statement is executed). However, execution of the second GOTO statement occurs within a block activation other than that whose designator was assigned to L. Execution of the second GOTO statement first uses the stack frame designator of L to terminate the block activation of B and restore the block activation of A. The second GOTO statement then transfers control to the statement labeled L1. If A were a recursive procedure with more than one activation, the statement GOTO L in B would restore the most recent activation of A. Note that a label variable that is given L as a value will denote the activation of A current at the moment L is assigned, which may not be A's most recent activation. Use of a label variable after its associated block has exited may cause unpredictable results.

A single, optionally signed integer constant in the range -32768 to +32767 may be used to subscript a label. An array of labels is declared by the occurrence of subscripted labels. The elements of the array are all the subscripted labels having the same name and appearing within the same block. The highest subscript used is the upper bound of the array. The lowest subscript used is the lower bound of the array. The number of integers between the lower bound and the upper bound, inclusive, is the extent of the array. The array contains one element of each integer in the extent, although there may not be a subscripted label corresponding to the element. If you refer to an undefined element, the result is unpredictable. For example:

      GOTO CASE(K); 
CASE(1):
   .
   .
   .
CASE(2):
   .
   .
   .
CASE(3):
   .
   .
   .
CASE(6):
   .
   .
   .

In this example, CASE is a one-dimensional array of statement labels containing six elements. Elements 4 and 5 are undefined and should not be used. Using an undefined element produces unpredictable results.

Label prefixes on PROCEDURE, FORMAT, BEGIN, and ENTRY statements cannot be subscripted.

Because the label array is declared by label prefixes, it cannot also be declared as a LABEL variable by appearing in a DECLARE statement.

Label values may be assigned, compared for equality or inequality, passed as arguments, and returned from functions, but no calculations or conversions can be performed on them. You may specify potential label values that can be assigned to a LABEL variable. They cannot be transmitted in stream I/O.

Previous Topic Next topic Print topic