From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!mx05.eternal-september.org!feeder.eternal-september.org!gegeweb.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Beginner issue.. Date: Sun, 16 Jun 2013 09:21:55 +0200 Organization: cbb software GmbH Message-ID: <1xwjeszj238ws.1x4a0ywxkq0ol.dlg@40tude.net> References: <5788c60d-fb8c-4058-9ae9-414dd77a3dc4@googlegroups.com> <93769622-5341-472e-8f08-c0121c38de5d@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: xkOZ88C3T5fLavXpgyt3vA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:15753 Date: 2013-06-16T09:21:55+02:00 List-Id: 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