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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,bbe592428babd509 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder3.cambriumusenet.nl!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.158.31.10.MISMATCH!newsfeed-0.progon.net!progon.net!uucp.gnuu.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 27 Apr 2010 17:30:44 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Integer overflow is int overflow (Re: Web browser in Ada) References: <02c2bf63-260d-4acc-bd58-c8fb8a591ec3@b6g2000yqi.googlegroups.com> <0bf9425c-32a1-4b93-b938-ae4a4e24a761@c21g2000yqk.googlegroups.com> <4bd1b090$0$7651$9b4e6d93@newsspool1.arcor-online.net> <4bd6d6e8$0$6892$9b4e6d93@newsspool2.arcor-online.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4bd70325$0$7666$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 27 Apr 2010 17:30:45 CEST NNTP-Posting-Host: 7bb856a7.newsspool1.arcor-online.net X-Trace: DXC=meiCNcKNFCEC4i^e1BZ=_Hic==]BZ:afN4Fo<]lROoRA<`=YMgDjhgBSP;f\ePnKaLnc\616M64>JLh>_cHTX3jMRSBO30S^eKH X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:11207 Date: 2010-04-27T17:30:45+02:00 List-Id: 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).