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,b3c479d8e293030d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.78.MISMATCH!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "Alex Mentis" Newsgroups: comp.lang.ada Subject: Re: Unconstrained base subtype questions Date: Thu, 31 Mar 2011 21:26:10 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <8762qzm1ya.fsf@ludovic-brenta.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 31 Mar 2011 21:26:10 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="TfaOIE1E70h9psK9x8LxRg"; logging-data="11255"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Oz7lo/WM0a9ZVIj5zwJkODL8+iTM2vS8=" User-Agent: XanaNews/1.19.1.269 Cancel-Lock: sha1:fBVfbPz6yVcgShd7xU2OzQYbkh8= Xref: g2news2.google.com comp.lang.ada:19609 Date: 2011-03-31T21:26:10+00:00 List-Id: Ludovic Brenta wrote: > "Alex Mentis" writes: > > The following does not cause a constraint error in my version of > > GNAT on my system: > > > > ... > > > > Integer_Result := (Integer'Last + Integer'Last) / 2; > > > > ... > > > > > > If I understand correctly, this is because the Integer operators are > > defined for operands of type Integer'Base, which is an unconstrained > > subtype and allows the operands to be stored in extended-length > > registers so that intermediate values in calculations do not > > overflow. > > > > My questions are: > > > > 1) Do I understand correctly what's going on? > > I suspect you compiled without the secret -gnato option No, I compiled with that option enabled. It still ran happily and produced the correct output. > > 2) Does the language make any guarantees about preventing spurious > > overflow, or am I just getting lucky with my compiler/architecture? > > If guarantees are made by the language, what are they? > > I'm not sure what you mean by "spurious overflow" (as opposed to > "overflow") but: By "spurious overflow" I mean overflow from intermediate results of a calculation in which the correct final result is actually still within the type constraints. > - during execution, there are two kinds of overflow checks. > Intermediate results must lie within the "base range of the type" > which, for all intents and purposes, is the full range of > [[Long_]Long_]Integer (ARM 4.5.4(20)). So, if an intermediate value > exceeds e.g. Integer'Last you get a Constraint_Error. Well, that's my question. In the calculation above, I clearly have an intermediate value that exceeds Integer'Last. And I tried something similar with Long_Long_Integer and still couldn't get an overflow error! So what is the actual limit on the base range of the type? Is it language defined, compiler defined, hardware defined, none of the above?