comp.lang.ada
 help / color / mirror / Atom feed
From: Marcus F <trenatos@gmail.com>
Subject: Re: Beginner issue..
Date: Sun, 16 Jun 2013 00:52:57 -0700 (PDT)
Date: 2013-06-16T00:52:57-07:00	[thread overview]
Message-ID: <10f60bd4-cb71-4d77-88cb-46781a3f6194@googlegroups.com> (raw)
In-Reply-To: <1xwjeszj238ws.1x4a0ywxkq0ol.dlg@40tude.net>

On Sunday, June 16, 2013 2:21:55 AM UTC-5, Dmitry A. Kazakov wrote:
> On Sun, 16 Jun 2013 00:00:33 -0700 (PDT), Marcus F wrote:
> 
> 
> 
> > On Sunday, June 16, 2013 1:54:29 AM UTC-5, Marcus F wrote:
> 
> >> 
> 
> >> I'm looking at a simple tutorial guide to pick up some basics of ADA, but
> 
> >> I ran into an issue that I don't understand.
> 
> 
> 
> OK, this is a GNAT Ada compiler pitfall almost anybody runs into.
> 
> 
> 
> When you compile an Ada program with GNAT, NEVER EVER forget to turn the
> 
> run-time integer overflow checks on. E.g. in your case, you should compile
> 
> your program as follows:
> 
> 
> 
>    gnatmake -gnato compute.adb
> 
> 
> 
> The switch -gnato instructs GNAT to check integer overflows, which is what
> 
> happens. After that the output would look like:
> 
> 
> 
>           1
> 
>           2
> 
>           4
> 
>           8
> 
>          16
> 
>          32
> 
>          64
> 
>         128
> 
>         256
> 
>         512
> 
>        1024
> 
>        2048
> 
>        4096
> 
>        8192
> 
>       16384
> 
>       32768
> 
>       65536
> 
>      131072
> 
>      262144
> 
>      524288
> 
>     1048576
> 
>     2097152
> 
>     4194304
> 
>     8388608
> 
>    16777216
> 
>    33554432
> 
>    67108864
> 
>   134217728
> 
>   268435456
> 
>   536870912
> 
>  1073741824
> 
> 
> 
> raised CONSTRAINT_ERROR : compute.adb:8 overflow check failed
> 
> 
> 
> Without checks on, you get an overflow. For a number of power of two the
> 
> overflow results in 0. 0*2=0, which is what you observe on the screen.
> 
> 
> 
> -- 
> 
> Regards,
> 
> Dmitry A. Kazakov
> 
> http://www.dmitry-kazakov.de

Thank you Dmitry!

Now I just need to figure out how to turn on the Integer Overflow checks..
(I'm using AdaGIDE, just hitting save, build, run)

  reply	other threads:[~2013-06-16  7:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-16  6:54 Beginner issue Marcus F
2013-06-16  7:00 ` Marcus F
2013-06-16  7:21   ` Dmitry A. Kazakov
2013-06-16  7:52     ` Marcus F [this message]
2013-06-16  7:55       ` Marcus F
2013-06-16  8:49         ` Dmitry A. Kazakov
2013-06-16 18:32           ` Marcus F
2013-06-16  7:30 ` Dirk Heinrichs
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox