next up previous contents index
Next: Arrays Up: Data Types Previous: Floodable Regions

Type Conversion

     

Type equivalence in ZPL is by name equivalence rather than structure equivalence. Anonymous types of identical declarations are treated as having the same name. The following example demonstrates the used of anonymous types:

    type array2d : array [1..5] of integer;

    var a : array2d;
        b : array [1..5] of integer;
        c : array [1..5] of integer;
        d : array [1..6] of integer;
        e : array [2..7] of integer;

    . . .

    a[] := b[];    -- legal
    b[] := c[];    -- legal
    c[] := d[];    -- illegal, arrays of different size
    a[] := e[];    -- illegal, anonymous use of different types

There are two aspects to type equivalence for parallel variables. First, the elements of parallel variables must be name equivalent. Second, the parallel variables must be rank equivalent, i.e., the parallel variables have the same number of dimensions and the size of any dimension of an r-value must be no larger than the size of the corresonding dimension of the l-value.

When different types are utilized in an expression ZPL follows the same type conversion rules as ANSI C. Generally speaking, variables of a type with a narrower range are converted to the type with a wider range to prevent loss of information. Assigning a variable of a wider range to a variable of a narrower range is allowed, yet the results are unpredictable and loss of information can occur. Booleans can be converted to integral values (Section 3.1 defines the integral data types) in which case true is converted to 1 and false is converted to 0. Integral values can also be interpreted as booleans, with zero converted to false and any non-zero value converted to true.

ZPL does not provide an implicit facility for casting one data type to another. Type conversion is not performed on procedure parameters, and any such type mismatches will be reported by the compiler. Explicit type conversion can be specified by using built-in functions such as to_float() and to_integer(). These functions are part of the standard context, as shown in Appendix B.



Kay Nettle
Fri Feb 21 21:14:29 CST 1997