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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Should exceeding the range of Integer wrap around a la C? Date: Mon, 21 May 2018 17:46:45 +0100 Organization: A noiseless patient Spider Message-ID: References: <7ba47ec1-28e7-43e1-83a0-2a4d2cf0fd92@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: h2725194.stratoserver.net; posting-host="36c50ea74cc9f27847d0e9609d64d90e"; logging-data="19566"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195A7UZLzmTrmAAhYCy71aTrzxP2kZ65i0=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (darwin) Cancel-Lock: sha1:2xs6iB5rn6mdUO/NRgGa3W5gaBI= sha1:I0m4zpFFrPjBnw8YGrKZ2Ce9Zl0= Xref: reader02.eternal-september.org comp.lang.ada:52549 Date: 2018-05-21T17:46:45+01:00 List-Id: Anh Vo writes: > On Monday, May 21, 2018 at 8:23:21 AM UTC-7, nrs...@gmail.com wrote: >> I expect this program to print powers of 2 until `X` exceeds the >> range of Integer. Instead, it seems to "wrap around" with the >> following (abbreviated) output: >> 1 >> 2 >> 4 >> [...] >> 268435456 >> 536870912 >> 1073741824 >> -2147483648 >> 0 >> 0 >> [...] >> 0 >> >> I am compiling with GNAT 4.9.2 on a Debian Linux system using `gnat >> make compute` with no further compiler flags. Are my expectations >> wrong, or is this incorrect behavior? > > A Constraint_Error must be raised. If not, it is a compiler bug. This isn't a bug, it's a feature of older GNATs; AdaCore thought that checking for overflow of machine integers would be too inefficient. The fact that (a) everyone puts -gnato in their options and (b) -gnato is now the default indicate that that thought was wrong (or, at any rate, became wrong a good while ago).