Matching Array Lower Bounds

Array parameters can be declared either with an undeclared lower-bound specification or with a formal lower-bound specification. Arrays with undeclared lower bounds are hereafter referred to as unbounded arrays. Arrays with formal lower bounds are hereafter referred to as simple arrays.

In the case of unbounded arrays, the lower-bound value of the array is provided during execution by the program that calls the procedure. In the case of simple arrays, the lower-bound value of the array is fixed during compilation, typically to a value of zero. The actual value of the lower-bound parameter for the simple array is ignored during execution.

If an unbounded array appears as a parameter to an imported or exported procedure, the system generates one or more hidden parameters that pass the actual lower bound for each dimension of the array. These hidden parameters are integer parameters that follow the array parameter and are passed by value.

The syntax for array specifications in the various programming languages is described in Unbounded and Simple Array Declarations.

Table 18. Unbounded and Simple Array Declarations

Language

Unbounded Array

Simple Array

ALGOL

ARRAY A[*];

ARRAY A[0];

C

float (*) [ ]

None

COBOL74

01 A BINARY.

77 B PIC S9(11) BINARY.

01 A BINARY.

COBOL85

01 A BINARY WITH LOWER-BOUNDS.

01 A BINARY.

FORTRAN77

REAL A(*).

None

NEWP

ARRAY A[*];

ARRAY A[0];

Pascal

var a: ARRAYTYPE;

None


Libraries and client programs written in COBOL85 can receive unbounded array parameters by including a LOWER-BOUNDS clause in the formal array declaration. A COBOL85 library always treats such an array parameter as if it had a lower bound of zero, regardless of the actual lower bound passed by the client program.

COBOL74 libraries and client programs can specify unbounded array parameters by adding a numeric parameter that receives the lower bound. In a COBOL74 client program, this extra parameter must occur immediately after the unbounded array in the CALL statement parameter list. In a COBOL74 library program, this extra parameter must occur immediately after the unbounded array in the USING clause of the PROCEDURE DIVISION. COBOL74 libraries always treat array parameters as if they had a zero lower bound, regardless of the value passed in the extra parameter.

Pascal array parameters can reference space in a data pool or in the heap. As a result, if a Pascal client program passes an array parameter to a library, some constructs in the library might result in incorrect references or cause overwrite corruption of other arrays stored in the same data pool or heap.

For example, suppose a Pascal client program passes an array A to an ALGOL library. In the exported ALGOL procedure, the expression POINTER(A) references the first element in the data pool or heap. By contrast, the expression POINTER(A[0]) correctly references the actual first element of the Pascal array A. Other constructs that can cause similar problems, if not carefully used, include the SIZE and REMAININGCHARS functions and the REPLACE, SCAN, and RESIZE statements. Note that no system function can return the size of a Pascal array.

Additional problems can arise if a Pascal client program passes an array parameter to a library written in a COBOL language. Like ALGOL libraries, COBOL libraries have no way of determining the upper bound of an array in the heap. However, COBOL libraries have the additional limitation that the lower bound of the array is always treated as zero, regardless of where the array starts in the data pool.