comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Integer overflow is int overflow (Re: Web browser in Ada)
Date: Tue, 27 Apr 2010 17:30:44 +0200
Date: 2010-04-27T17:30:45+02:00	[thread overview]
Message-ID: <4bd70325$0$7666$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <ddec5d2c-1d09-462c-a1ae-d11470022e14@r1g2000yqb.googlegroups.com>

On 27.04.10 16:00, AdaMagica wrote:
> But Standard.Integer is an integer ;-)
> 
>   Very_Big   : constant :=      Integer'Last +      Integer'Last;  --
> "+" of Integer
>   Even_Bigger: constant := Long_Integer'Last + Long_Integer'Last;  --
> "+" of Long_Integer
>   Illegal    : constant := Long_Integer'Last +      Integer'Last;  --
> "+" mixing

Are these really of type Standard.Integer?  I think (after rummaging
through the RM) they are not.
These are named numbers, and their declaration has no effect.
They are of type universal_integer (unconstrained?) which has no name.
And they cannot overflow then.

The builtin "+" can deliver the sum of any static constants
within capacity constraints of the compiler.

package Big is

   Z : constant := 2 ** 1_000_000_000;

   Y : constant := 2 ** 10_000;

   A : constant := 9 ** (9 ** 9);

   B : constant := Long_Long_Integer'Succ (2**63 - 1);

   Bigger : constant Boolean := B > Long_Long_Integer'Last;

end Big;

Compiling: big.ads (source file time stamp: 2010-04-27 14:53:49)

     5.    Z : constant := 2 ** 1_000_000_000;
                             |
        >>> static value too large, capacity exceeded

     7.    A : constant := 9 ** (9 ** 9);
                             |
        >>> static value too large, capacity exceeded


Unavailable:
  for D'Size use ...;
  pragma Inspection_Point (...);

Big.Bigger is True.

My conclusions would be that:

Standard.Integer is a constrained subtype. Its objects are
not like (what is commonly known as) integers, a set that can
be extended at will.
They cannot overflow in Ada mode.  There is no wrap-around.

Named numbers of no-name type universal_integer
cannot overflow, their value is determined by the compiler,
they are not objects, and they can hit compiler capacity limits.

So neither Standard.Integer nor universal_integer is an integer.

Nor is C's int.  Still assuming C's int is like integers,
encouraged by how "int" and "integer" are used interchangeably
in talks and writings, leads to to overflow (this is my
hypothesis).




  reply	other threads:[~2010-04-27 15:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-23  8:03 Web browser in Ada Gautier write-only
2010-04-23 13:56 ` Maciej Sobczak
2010-04-23 14:37   ` Georg Bauhaus
2010-04-27 11:41     ` Martin Krischik
2010-04-27 12:22       ` Georg Bauhaus
2010-04-27 14:00         ` AdaMagica
2010-04-27 15:30           ` Georg Bauhaus [this message]
2010-04-27 16:13             ` Integer overflow is int overflow (Re: Web browser in Ada) Dmitry A. Kazakov
2010-04-27 17:09               ` Georg Bauhaus
2010-04-27 17:56                 ` Dmitry A. Kazakov
2010-04-23 21:33   ` Web browser in Ada Gautier write-only
2010-04-24  0:38     ` Peter C. Chapin
2010-04-25  5:38       ` Gautier write-only
2010-04-25 16:24         ` Peter C. Chapin
2010-04-25 10:41       ` Georg Bauhaus
2010-04-25 16:29         ` Peter C. Chapin
2010-04-26 15:37       ` Warren
2010-04-24  9:51 ` leonid
2010-04-25  5:04   ` Gautier write-only
replies disabled

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