[M3devel] index array by longint?

Tony Hosking hosking at cs.purdue.edu
Sun Jan 10 05:22:44 CET 2010


That's very nice!  I like it.  I think we can use it....

Right now I am tracking bugs in range checking.  Some were introduced by my LONGINT changes (sigh!) but others appear to have been around a while before that.

For example:

VAR s: CARDINAL := LAST(INTEGER);
BEGIN INC(s) END;

did not result in a run-time error.  I think I have fixed that now (commit to come).

But, even worse:

VAR s: CARDINAL := LAST(INTEGER);
BEGIN WITH x = s DO x := VAL(ORD(x) + 1, CARDINAL) END END;

also does not give a run-time error.

The result is that you can store FIRST(INTEGER) in a CARDINAL.  Yikes!

On 9 Jan 2010, at 21:54, Rodney M. Bates wrote:

> When writing my original proposal, I agonized at length over whether
> to allow (subranges of) LONGINT to be the index type of an array type.  In the
> end, I decided that gave a poor ratio of practical benefit to language
> and implementation complexity.
> 
> However, note, from 2.6.3, "Designators,
> 
> "a[i]
>    denotes the (i + 1 - FIRST(a))-th element of the array a. The expression a[i] is a
>    designator if a is, and is writable if a is. The expression i must be assignable
> --------------------------------------------------------------------------^
>    to the index type of a. The type of a[i] is the element type of a."
> 
> So, by existing rules about assignability, when referring to an element of an
> array, the subscript expression could have base type LONGINT, and would just
> be "assigned" in the usual way to the index type, a subrange of INTEGER.
> This is one of the dozen or so places assignability is used in the language.
> 
> 
> 
> Jay K wrote:
>> Index array by longint?
>> With runtime check that it is <= LAST(INTEGER)?
>>  Or really, with runtime bounds check against the array size.
>> Seems reasonable?
>> Aids the rd/wr change.
>> A little bit of pain to implement..unless INTEGER and LONGINT have a common base...
>>   - Jay

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100109/ce43d885/attachment-0002.html>


More information about the M3devel mailing list