[net.lang.mod2] THe type of Indexes in Open Array Parameters

PATTIS@WARD.CS.WASHINGTON.EDU (Richard Pattis) (10/03/86)

What is the type of the index in open array parameters?  How can you justify
your answer (quotes from Wirth)? This problem came up in the following context:
I have been using integer variables to index open array parameters; but the
PCollier compiler requires that open array parameters be accessed by using
the cardinal type.  I tried to convince myself that this was an error, but I
couldn't see anything in Wirth's book that directly supported my position.

To access declared types using integer indexes, I can write (according to the
new Modula-2 syntax) TYPE A = ARRAY INTEGER[1..10] OF T. The question could
be resolved if Wirth says that indexes must be assignment compatible (but not
compatible) with their declared (or implied) index types.

Rich
-------

farnum@renoir.Berkeley.EDU (Charles D. Farnum) (10/03/86)

In article <12243873849.8.PATTIS@WARD.CS.WASHINGTON.EDU> PATTIS@WARD.CS.WASHINGTON.EDU (Richard Pattis) writes:
>What is the type of the index in open array parameters?  How can you justify
>your answer (quotes from Wirth)? ...

According to the third edition of ``Programming in Modula-2'', p. 152,
section 8.1 of the Report:

    ...the designator A[E] denotes that component of A whose index is the 
    current value of the expression E.  The index type of A must be
    _assignment_compatible_ [emphasis Wirth's] with the type of E...

The index type of an open array thus becomes academic; if we assume that
it is some subrange of CARDINAL or INTEGER, then it doesn't matter which
choice we make since subranges of CARDINAL and INTEGER are assignment
compatible (section 9.1).

  /charlie