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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.50.157.35 with SMTP id wj3mr11157690igb.6.1452124094765; Wed, 06 Jan 2016 15:48:14 -0800 (PST) X-Received: by 10.182.231.229 with SMTP id tj5mr317847obc.13.1452124094745; Wed, 06 Jan 2016 15:48:14 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!h5no879503igh.0!news-out.google.com!f6ni45669igq.0!nntp.google.com!h5no879492igh.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 6 Jan 2016 15:48:14 -0800 (PST) In-Reply-To: <87egduhjiv.fsf@theworld.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=149.32.224.36; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 NNTP-Posting-Host: 149.32.224.36 References: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com> <87poxixqmy.fsf@theworld.com> <112f5e6c-35c1-483a-b8dd-24f5f76dc6ce@googlegroups.com> <084197af-8e37-4250-a083-b45bd9ab4609@googlegroups.com> <87egduhjiv.fsf@theworld.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <9a74db40-302a-4122-a464-68c736e9126b@googlegroups.com> Subject: Re: Instantiating package problems From: Anh Vo Injection-Date: Wed, 06 Jan 2016 23:48:14 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:29038 Date: 2016-01-06T15:48:14-08:00 List-Id: On Wednesday, January 6, 2016 at 6:25:47 AM UTC-8, Bob Duff wrote: > Anh Vo writes: >=20 > > On Tuesday, January 5, 2016 at 7:31:00 PM UTC-8, Andrew Shvets wrote: > >> On Monday, January 4, 2016 at 3:49:32 PM UTC-5, Anh Vo wrote: > >> > On Sunday, January 3, 2016 at 4:07:30 PM UTC-8, Andrew Shvets wrote: > >> > > Hi Bob, > >> > >=20 > >> > > Thanks for writing back. This is the entire example: > >> > > http://pastebin.com/GEJT3WzL > >> > =20 > >> > Just recommend to add a precondition to function Division as shown b= elow. By the way, this feature is part of latest Ada (Ada 2012). In additio= n, you should think about adding precondition to other operations such as A= ddition where Input1 + Input2 <=3D Integer'Last and Input1 + Input2 >=3D In= teger'Last.=20 > >> >=20 > >> > function Division( > >> > Input1 : in Integer; > >> > Input2 : in Integer) > >> > return Integer > >> > with pre =3D> Input2 /=3D 0; >=20 > I prefer predicates in a case like that: >=20 > subtype Nonzero is Integer with Predicate =3D> Nonzero /=3D 0; >=20 > And then Input2 can be of subtype Nonzero. (Predicate is specific to > GNAT; use Static_Predicate if you want to conform to the Ada standard.) >=20 > >> I'm not sure that that worked. I added it to my ads file and after > >> compilation and then re-running the application, this is what I got: > >>=20 > >> .... > >>=20 > >> Division: 4 > >>=20 > >>=20 > >> raised CONSTRAINT_ERROR : calculator.adb:33 divide by zero > >>=20 > >> Shouldn't the division function been prevented from running the actual= division operation beforehand? > > > > The preconditions and postconditions are controlled by pragma > > Assertion_Policy. Thus, pragma Assertion_Policy(Check) must be added at= the top > > of the package specification. Absent of this pragma is equivalent to pr= agma > > Assertion_Policy (Ignore). That means these conditions are ignored. By = the way, > > ASSERTION_ERROR exception would be raised instead of CONSTRAINT_ERROR. >=20 > I wouldn't bother fooling about with Assertion_Policy. > Just use the -gnata switch. I like to stay away from compiler dependence as much as I can. Thus, I chos= e to stay with Ada Standard in this case. =20 > If you do use Assertion_Policy, you probably want it in a global > configuration file, so it applies to all of your code. I agree that this is a good advice for large number of packages. Anh Vo