comp.lang.ada
 help / color / mirror / Atom feed
From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: Instantiating package problems
Date: Wed, 6 Jan 2016 21:41:31 -0800 (PST)
Date: 2016-01-06T21:41:31-08:00	[thread overview]
Message-ID: <2ae043b6-e745-4f27-a9ab-cc183a25ca56@googlegroups.com> (raw)
In-Reply-To: <768bb8bd-ed12-4235-a663-fa71fcb42795@googlegroups.com>

On Wednesday, January 6, 2016 at 8:41:38 PM UTC-8, Andrew Shvets wrote:
> On Wednesday, January 6, 2016 at 12:07:15 AM UTC-5, Anh Vo wrote:
> > On Tuesday, January 5, 2016 at 9:00:50 PM UTC-8, Andrew Shvets wrote:
> > > On Tuesday, January 5, 2016 at 11:52:00 PM UTC-5, Anh Vo wrote:
> > > > 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,
> > > > > > > 
> > > > > > > Thanks for writing back.  This is the entire example:
> > > > > > > http://pastebin.com/GEJT3WzL
> > > > > >  
> > > > > > Just recommend to add a precondition to function Division as shown below. By the way, this feature is part of latest Ada (Ada 2012). In addition, you should think about adding precondition to other operations such as Addition where Input1 + Input2 <= Integer'Last and Input1 + Input2 >= Integer'Last. 
> > > > > > 
> > > > > >   function Division(
> > > > > >     Input1 : in Integer;
> > > > > >     Input2 : in Integer)
> > > > > >       return Integer
> > > > > >    with pre => Input2 /= 0;
> > > > > > 
> > > > > > Anh Vo
> > > > > 
> > > > > 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:
> > > > > 
> > > > > ....
> > > > > 
> > > > >  Division:        4
> > > > > 
> > > > > 
> > > > > raised CONSTRAINT_ERROR : calculator.adb:33 divide by zero
> > > > > 
> > > > > 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 pragma Assertion_Policy (Ignore). That means these conditions are ignored. By the way, ASSERTION_ERROR exception would be raised instead of CONSTRAINT_ERROR.
> > > 
> > > This is how the body looks like now:
> > > http://pastebin.com/Mt0E0HAD
> > > 
> > > I'm still getting a constraint error.
> > 
> > I only saw the pragma placed inside the package body. It should be placed in the package specification.
> 
> Alright, I put the pragma before each package keyword (in the body and the declaration) and this is what I got:
> 
> $ gnatmake -g main.adb
> gcc -c -g main.adb
> calculator.ads:5:01: pragma "assertion_policy" is not in declarative part or package spec
> gnatmake: "main.adb" compilation error

what I meant was on top of the package specification as shown below.

pragma Assertion_Policy (Check);
with Ada.Text_IO;

package Calculator is
--...
end Calculator;

  reply	other threads:[~2016-01-07  5:41 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-03 18:40 Instantiating package problems Andrew Shvets
2016-01-03 20:27 ` Georg Bauhaus
2016-01-03 21:21   ` Andrew Shvets
2016-01-03 21:04 ` Jeffrey R. Carter
2016-01-03 21:27   ` Andrew Shvets
2016-01-03 22:39     ` Jeffrey R. Carter
2016-01-03 22:08 ` Bob Duff
2016-01-04  0:07   ` Andrew Shvets
2016-01-04  0:30     ` Andrew Shvets
2016-01-04 13:43       ` G.B.
2016-01-04 14:23       ` Brian Drummond
2016-01-04 20:49     ` Anh Vo
2016-01-04 21:10       ` Dmitry A. Kazakov
2016-01-04 22:39         ` Anh Vo
2016-01-05  1:42           ` Anh Vo
2016-01-05  7:35           ` Dmitry A. Kazakov
2016-01-06  2:46       ` Andrew Shvets
2016-01-06  8:53         ` Dmitry A. Kazakov
2016-01-06  3:30       ` Andrew Shvets
2016-01-06  4:51         ` Anh Vo
2016-01-06  4:54           ` Anh Vo
2016-01-06  5:00           ` Andrew Shvets
2016-01-06  5:07             ` Anh Vo
2016-01-07  4:41               ` Andrew Shvets
2016-01-07  5:41                 ` Anh Vo [this message]
2016-01-09 20:14                   ` Andrew Shvets
2016-01-10 19:43                     ` Andrew Shvets
2016-01-10 21:38                       ` Jeffrey R. Carter
2016-01-10 21:50                       ` Georg Bauhaus
2016-01-10 21:58                         ` Andrew Shvets
2016-01-06 13:07             ` G.B.
2016-01-07  4:42               ` Andrew Shvets
2016-01-06 14:25           ` Bob Duff
2016-01-06 23:48             ` Anh Vo
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox