[M3devel] integer overflow
Jay K
jay.krell at cornell.edu
Tue Jan 12 21:51:46 CET 2010
> subranges allow suppressing array index checks
I didn't know that.
Sounds reasonable.
I haven't contradicted it, have I?
That does point out that indexing an array with an INTEGER need bounds checks on both ends though.
Probably a FOR loop can optimize though -- no need to check the lower bound more than once or somesuch.
Gotta go,
- Jay
----------------------------------------
> Date: Tue, 12 Jan 2010 15:37:49 -0500
> From: hendrik at topoi.pooq.com
> To: m3devel at elegosoft.com
> Subject: Re: [M3devel] integer overflow
>
> On Tue, Jan 12, 2010 at 08:21:27PM +0000, Jay K wrote:
>>
>> Range checking and overflow checking I think are different.
>>
>>
>> TYPE T1 = [1..6];
>> a:T1 := 7; (* range check error *)
>> b:T1 := 6;
>> c:T1 := 1;
>> d:T1 := b + c; (* range check error *)
>> e:T1 := c - b; (* range check error *)
>> f:ARRAY [1..4] OF INTEGER;
>> f[b] := 0; (* range check error *)
>> g:INTEGER := LAST(INTEGER) - 5 + a; (* overflow *)
>>
>>
>> But anyway, yes it will be slower, but I believe it should be mandatory, at least in safe modules, it is needed for safety, and I doubt it'll be *noticably* slower for the vast majority of code.
>>
>>
>> Initially it'll probably be a command line option or such.
>>
>>
>> Or maybe it isn't a safety issue?
>> As long as one has checks on array indexing? Which I'm sure we do.
>
> I always thought one of the points about declared ranges (instead of
> making everything just int, as C does) was to enable one to suppress
> most of the array indexing checks safely.
>
> -- hendrik
More information about the M3devel
mailing list