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: 103376,8df81176cbd821cd,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!news-zh.switch.ch!switch.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Range checking not working as expected? Date: Thu, 28 Jul 2005 17:00:13 +0200 Organization: CERN - European Laboratory for Particle Physics Message-ID: NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1122562812 14098 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050724 Red Hat/1.7.10-1.1.3.1.SL3 X-Accept-Language: en-us, en Xref: g2news1.google.com comp.lang.ada:3817 Date: 2005-07-28T17:00:13+02:00 List-Id: Hello, Consider this: with Ada.Text_IO, Ada.Integer_Text_IO; procedure Overflow is A : Integer := 0; D : constant Integer := 500000000; begin for I in 1..20 loop Ada.Integer_Text_IO.Put(A); Ada.Text_IO.New_Line; A := A + D; end loop; end Overflow; On my machine (PC+Linux+GNAT) it produces the following output: 0 500000000 1000000000 1500000000 2000000000 -1794967296 -1294967296 -794967296 -294967296 205032704 705032704 1205032704 1705032704 -2089934592 -1589934592 -1089934592 -589934592 -89934592 410065408 910065408 Not good - I expected constraint error instead of going round the counter. What has really confused me is that declaring A as Natural gives the same effect. Further investigation with the following declarations: type MyType is range 0..Integer'Last; A : MyType := 0; (and type casts later, when necessary) showed exactly the same effect. Following this path, I tried this: type MyType is range 0..Integer'Last - 1; A : MyType := 0; And *now* I got what I wanted - the constraint error. What's going on? Well, I understand the low-level mechanics of this difference (and also why this might be a border-case for the compiler), but the question is rather high-level: what does *that* mean? :) -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/