gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] no overflow checking ?


From: Fischlin Andreas
Subject: Re: [Gm2] no overflow checking ?
Date: Thu, 28 Apr 2011 16:32:01 +0000

Dear Arnauld,

Modula-2's real strength is in checking at compile time as much as possible. 
Catching run time errors are a matter of the implementation, i.e. the code the 
compiler generates and has little to do with the language itself. Please 
consider this distinction.

With respect to integer overflow, there have been and are various philosophies. 
Integer overflow is something which may or may not by default be caught by the 
code the compiler generates. Since integer overflow may be expensive on certain 
hardware, some earlier Modula-2 compilers did not catch it by default. However, 
what is in general much more important is that the programmer has control over 
the behavior of the compiler, since certain algorithms, e.g. congruential 
linear generators for pseudo random numbers may depend on integer overflow. 
Thus, even if by default a compiler catches integer overflow, a good Modula-2 
compiler should allow you to suppress such checking if needed, best for a few 
statements within the source code only, i.e. so-called compilation options 
inserted in form of special comments. E.g.

        (*$R+*)  enables array index, subrange and pointer checks  (default)
        (*$R-*)   enables array index, subrange and pointer checks
        (*$V+*)  enables integer overflow check  (default?)
        (*$V-*)  disables integer overflow check

This is e.g. what MacMETH (http://www.sysecol.ethz.ch/ramses/layer/MacMETH) 
does (except integer overflow is off by default, since too expensive).

Hope this helps and I hope Gaius has considered these considerations when 
"fixing the bug".

Regards,
Andreas


ETH Zurich
Prof. Dr. Andreas Fischlin
Systems Ecology - Institute of Integrative Biology
CHN E 21.1
Universitaetstrasse 16
8092 Zurich
SWITZERLAND

address@hidden
www.sysecol.ethz.ch

+41 44 633-6090 phone
+41 44 633-1136 fax
+41 79 221-4657 mobile

             Make it as simple as possible, but distrust it!
________________________________________________________________________



On 20/Apr/2011, at 10:07 , Arnauld Michelizza wrote:

> Hi guys,
> 
> while learning modula-2, I wanted to test how binaries compiled with
> gm2 deals with overflows.
> As I understood, modula-2 strengh is that it can prevent overflows
> (integer-, buffer-, heap-) with runtime bounds checking.
> However, I didn't found how to do that with gm2. For example, here is
> a very short program that add 2 values :
> 
> ----- [code] -----
> VAR
>       x, y, res : INTEGER;
> BEGIN
>       WriteString("x> ");
>       ReadInt(x);
> 
>       WriteString("y> ");
>       ReadInt(y);
> 
>       res := x + y;
>       WriteString("x+y> ");
>       WriteInt(res, 1);
>       WriteLn();
> 
> END test.
> ----- [code] -----
> 
> And here is the integer overflow :
> 
>  am$ ./a.out
>   x> 2147483647
>  y> 1
>  x+y> -2147483648
> 
> I think I missed something....
> Any help ?
> 
> Arnauld
> 
> _______________________________________________
> gm2 mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/gm2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]