Contents | Prev | Next | Index
A type T may be defined as a subrange of another basic type (except real types) or of another enumeration type by the specification of the lowest and the highest value in the subrange.
subrange_type ::= [ const_expr .. const_expr ] ::= base_type [ const_expr .. const_expr ] base_type ::= qualident |
The first constant defines the lower bound, and it must not be greater than the defined upper bound. The resulting type T1 of the bounds is known as the base type of T, and all operators applicable to operands of type T1 are also applicable to operands of type T. However, if a value is assigned to a variable of type T1, it must lie within the subrange interval. It is possible to explicitly specify a base type identifier preceding the subrange expression. If it is omitted, and if the lower bound is a non-negative integer, than the base type is taken to be a cardinal type, else if it is negative, an integer type is taken as the base type. (See -S2 and -S4 compiler switches or $S2 and $S4 compiler directives for more details).
A type T1 is compatible with T, if one is a subrange of the other, or if both are the same type, or both are subranges of the same base type.
Examples of subrange types:
[0 .. N-1]["A" .. "Z"]
[Monday .. Friday]
Contents | Prev | Next | Index
Canterbury Modula-2 for Java (Last documentation update
Feb 8, 2000)
Copyright © 1998 Mill Hill &
Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com