comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Beginner issue..
Date: Sun, 16 Jun 2013 09:21:55 +0200
Date: 2013-06-16T09:21:55+02:00	[thread overview]
Message-ID: <1xwjeszj238ws.1x4a0ywxkq0ol.dlg@40tude.net> (raw)
In-Reply-To: 93769622-5341-472e-8f08-c0121c38de5d@googlegroups.com

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

  reply	other threads:[~2013-06-16  7:21 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 [this message]
2013-06-16  7:52     ` Marcus F
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