From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: Should exceeding the range of Integer wrap around a la C?
Date: Mon, 21 May 2018 08:45:17 -0700 (PDT)
Date: 2018-05-21T08:45:17-07:00 [thread overview]
Message-ID: <f8fed8fd-a64a-4b4e-a400-c24ef83bf942@googlegroups.com> (raw)
In-Reply-To: <7ba47ec1-28e7-43e1-83a0-2a4d2cf0fd92@googlegroups.com>
On Monday, May 21, 2018 at 8:23:21 AM UTC-7, nrs...@gmail.com wrote:
> Hi all,
>
> I'm brand-new to Ada coming from a Fortran & Python background - just starting to write some trivial tutorial programs. I'm trying to understand the output of following program (copied from the "Lovelace" Ada95 tutorial):
>
> -- compute.adb
> -- Demonstrate a trivial procedure, with another nested inside.
> with Ada.Text_IO, Ada.Integer_Text_IO;
> use Ada.Text_IO, Ada.Integer_Text_IO;
>
> procedure Compute is
>
> procedure Double(Item : in out Integer) is
> begin -- procedure Double
> Item := Item * 2;
> end Double;
>
> X : Integer := 1; -- Local variable X of type Integer
>
> begin -- procedure Compute
> loop
> Put(X);
> New_Line;
> Double(X);
> end loop;
> end Compute;
>
> 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.
Anh Vo
next prev parent reply other threads:[~2018-05-21 15:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-21 15:23 Should exceeding the range of Integer wrap around a la C? nrs5134
2018-05-21 15:27 ` Jacob Sparre Andersen
2018-05-21 15:45 ` Anh Vo [this message]
2018-05-21 16:46 ` Simon Wright
2018-05-21 18:47 ` Anh Vo
2018-05-21 15:57 ` Lucretia
2018-05-21 16:49 ` Simon Wright
2018-05-21 19:11 ` Paul Rubin
2018-05-22 0:39 ` Jere
2018-05-22 0:58 ` Dan'l Miller
2018-05-22 1:36 ` Paul Rubin
2018-05-21 20:43 ` nrs5134
2018-05-22 17:52 ` Björn Lundin
2018-05-22 20:11 ` nrs5134
2018-05-22 20:23 ` Björn Lundin
2018-05-23 7:35 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox