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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,32c6d2fb891775fc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-28 06:14:54 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.stueberl.de!newsfeed.freenet.de!news.tu-darmstadt.de!fu-berlin.de!uni-berlin.de!adsl-213-200-246-247.cybernet.CH!not-for-mail From: Vinzent 'Gadget' Hoefler Newsgroups: comp.lang.ada Subject: Re: Modular integers Date: Tue, 28 Oct 2003 15:13:25 +0100 Organization: JeLlyFish software Message-ID: References: Reply-To: v.hoefler@acm.org NNTP-Posting-Host: adsl-213-200-246-247.cybernet.ch (213.200.246.247) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de 1067350485 35193071 213.200.246.247 (16 [175126]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:1774 Date: 2003-10-28T15:13:25+01:00 List-Id: Lars wrote: >Why couldn't the compiler insert code that checks what the upper limit = of >the type is, It does, if necessary. AFAICS in your case it isn't: The upper limit of your subtype is the same as that of the base type which is a modular type. So where would you expect the overflow? You don't get rid of the modulo-operation just by defining a sub type. >then substracts the current value of the variable from the >upper limit to see if the difference is bigger or equal to the number = you >want to add? If it is not, it could throw an exception ... Why should it? No thinkable result of the modulo 2**64 operation would overflow your new range constraint for the subtype: IOW: "(A + 1) mod 2**64 in 0 .. 2**64 - 1" is always true. But try this with a subtype with a range only up to 2**64 - 2, this *will* give you the expected overflow: |with Ada.Text_IO; | |procedure t is | type X_Base is mod 2**64; | subtype X_1 is X_Base range 0 .. 2**64 - 1; | subtype X_2 is X_Base range 0 .. 2**64 - 2; | | A : X_Base; | B : X_1; | C : X_2; | |begin | A :=3D X_Base'Last; | Ada.Text_IO.Put (X_Base'Image (A)); | A :=3D A + 1; | Ada.Text_IO.Put (X_Base'Image (A)); | =20 | B :=3D X_1'Last; | Ada.Text_IO.Put (X_Base'Image (B)); | B :=3D B + 1; | Ada.Text_IO.Put (X_Base'Image (B)); | =20 | C :=3D X_2'Last; | Ada.Text_IO.Put (X_Base'Image (C)); | C :=3D C + 1; | Ada.Text_IO.Put (X_Base'Image (C)); |end t; compiled with GNAT3.15p gives: | 18446744073709551615 0 18446744073709551615 0 18446744073709551614 | |raised CONSTRAINT_ERROR : t.adb:25 range check failed Isn't that the expected result? Vinzent.