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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,99a0564a79f2932b,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!x5g2000yqk.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Type of subtraction operator Date: Thu, 28 May 2009 14:23:52 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8ae800c6-4307-4dc5-bf6b-d97101ae8521@x5g2000yqk.googlegroups.com> NNTP-Posting-Host: 83.76.152.206 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1243545832 11809 127.0.0.1 (28 May 2009 21:23:52 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 28 May 2009 21:23:52 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x5g2000yqk.googlegroups.com; posting-host=83.76.152.206; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.10) Gecko/2009042315 Firefox/3.0.10,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6087 Date: 2009-05-28T14:23:52-07:00 List-Id: According to 4.5.3/2, each numeric type has a subtraction operator with this specification: function "-"(Left, Right : T) return T This means that the type of difference is the same as the type of operands. Which means that if T is Natural, then I should expect CONSTRAINT_ERROR when the result of subtraction is less than 0. But it does not happen: with Ada.Text_IO; procedure Test is X : Natural := 5; Y : Natural := 7; Z : Integer := X - Y; -- here the result is not in Natural'Range begin Ada.Text_IO.Put_Line (Integer'Image (Z)); end Test; The above happily prints -2. I thought initially that it is a subtype that is responsible for this, but defining My_Natural type as a completely new type (with appropriate type cast when Z is initialized) gives the same result. I conclude that the effective type of difference (the return type of the "-" operator) is T'Base instead of T. Is that right? Is this a bug in AARM or did I misunderstand something? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada