HP 3000 Manuals

Conformant Array Parameters [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

Conformant Array Parameters 

A conformant array parameter is a formal array parameter defined by a
conformant array schema (the syntax appears in the HP Pascal/iX Reference 
Manual or the HP Pascal/HP-UX Reference Manual).  Its actual parameter
must be an array variable that conforms to the schema.

An array variable conforms to a conformant array schema if all of the
following are true:

   *   The variable and the schema are both PACKED, or neither is PACKED.

   *   The index types of the variable and the schema are compatible (as
       defined in the
       HP Pascal/iX Reference Manual or the HP Pascal/HP-UX Reference 
       Manual).

   *   The bounds of the index type of the variable are within the bounds
       of the index type of the schema.

   *   The element types of the variable and the schema are the same,
       unless the element type of the schema is another schema.  If the
       element type of the schema is another schema, the element type of
       the variable conforms to the other schema.

Example 1 

     TYPE
        itype = 0..20;
        jtype = 'a'..'z';
        ktype = 0..5;

     VAR
        var1 : ARRAY [0..10] OF integer;

     PROCEDURE p (yes  : ARRAY [lb1..ub1 : itype] OF integer;
                  no1  : PACKED ARRAY [lb3..ub3 : itype] OF integer;
                  no2  : ARRAY [lb4..ub4 : jtype] OF integer;
                  no3  : ARRAY [lb5..ub5 : ktype] OF integer;
                  no4  : ARRAY [lb6..ub6 : itype] OF real;
                  no5  : ARRAY [lb7..ub7 : itype;
                                lb8..ub8 : itype] OF integer);

The array variable var1 conforms to the schemas of the conformant array
parameter yes.  Var1 and the schema of yes have the same element type,
and 0..10 is within the bounds of itype.

The variable var1 does not conform to the schemas of conformant array
parameters no1, no2, no3, no4, and no5.  The following table gives the
reasons for nonconformance.

Parameter     Why var1 Does Not Conform to Schema 

no1           Schema is PACKED and var1 is not PACKED.

no2           Index types of var1 and schema are not compatible.

no3           Bounds of index type of var1 are not within bounds of index
              type of schema.

no4           Element types of var1 and schema are different.

no5           Schema specifies two dimensions, and var has only one
              dimension.

Like array declarations, schemas can specify dimensions in syntactically
different but structurally equivalent ways.

Example 2 

     VAR
        var1 : ARRAY [3..5,1..10] OF integer;
        var2 : ARRAY [3..5] OF ARRAY [1..10] OF integer;

     PROCEDURE p (yes1 : ARRAY [lb1..ub1 : itype] OF
                         ARRAY [lb2..ub2 : itype] OF integer;
                  yes2 : ARRAY [lb3..lb3 : itype;
                                lb4..ub4 : itype] OF integer;
                  no1  : ARRAY [lb5..ub5 : itype] OF integer;
                  no2  : ARRAY [lb6..ub6 : itype;
                                lb7..ub7 : itype;
                                lb8..ub8 : itype] OF integer);

The declarations of the array variables var1 and var2 are structurally
equivalent, as are the schemas of conformant array parameters yes1 and
yes2.  Both var1 and var2 conform to the schemas of yes1 and yes2.
Neither var1 nor var2 conforms to the schema of no1 or no2.

When a conformant array schema is a formal parameter, its bounds are also
formal parameters.  They are read-only parameters.  The actual parameter
for the formal conformant array schema is an array, and its bounds are
the actual parameters of the formal bounds parameters.

Example 3 

     TYPE
        itype = 0..20;

     VAR
        v : ARRAY [0..10] OF integer;

     PROCEDURE p (x  : ARRAY [lb..ub : itype] OF integer);

     BEGIN
        p(v);
     END;

       The conformant array schema x is a formal parameter, so its
       bounds, lb and ub are read-only formal parameters.  The array v is
       the actual parameter for x.  The lower bound of v, zero, is the
       actual parameter for lb.  The upper bound of v (10) is the actual
       parameter for ub.

When HP Pascal passes an actual parameter to a formal conformant array
parameter of more than one dimension, it also passes one hidden parameter
for each inner dimension that is itself a conformant array.  See "Hidden
Parameters"  for more information.



MPE/iX 5.0 Documentation