[M3devel] integer overflow and for loops

Tony Hosking hosking at cs.purdue.edu
Wed Jan 13 16:47:19 CET 2010


Their is a fine line to tread here between prohibiting perceived "bad" things happening and leaving the language design permissive enough to have an efficient implementation.  In the case of overflow I am not convinced it is so evil that it should be prohibited in the implementation.  In fact, one can argue that because current hardware does not uniformly treat integer overflow in ways that yield to efficient implementations the retaining the ambiguity is the right compromise.  This does not make the language any less safe.  A programmer cannot safely conjure values out of thin air.  And so long as he/she understands about integer overflow then the effects are at least entirely predictable.  Gguard against overflow is straightforward enough to do:

VAR upper: [0..LAST(INTEGER)-1] := bound;
FOR j = lower TO upper DO ... END;

On 13 Jan 2010, at 02:33, Roland Illig wrote:

> Jay K schrieb:
>> http://www.roland-illig.de/articles/modula-3-for-loop.pdf
> 
> My main point in that article was not the integer overflow but the fact of having an ugly sentence like "don't use the FOR loop for large numbers" in the language definition. Additionally, one would not expect the FOR loop to loop endlessly. These are the things I wanted to fix back then.
> 
> Roland




More information about the M3devel mailing list