comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: SPARK - runtime checks question
Date: Fri, 19 Jun 2009 11:33:32 -0700 (PDT)
Date: 2009-06-19T11:33:32-07:00	[thread overview]
Message-ID: <14f911e0-bd4c-4068-bae7-3d234cbed652@x1g2000prh.googlegroups.com> (raw)
In-Reply-To: 8d79ac48-d35d-4717-aca3-68f036de0de3@f16g2000vbf.googlegroups.com

On Jun 19, 8:26 am, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> Consider the following:
>
> -- my_package.ads:
> package My_Package is
>    function Distance (X : in Natural; Y : in Natural) return Natural;
> end My_Package;
>
> -- my_package.adb:
> package body My_Package is
>
>    function Distance (X : in Natural; Y : in Natural) return Natural
>    is
>       Result : Natural;
>    begin
>       if X > Y then
>          Result := X - Y;    // line 8
>       else
>          Result := Y - X;    // line 10
>       end if;
>       return Result;
>    end Distance;
>
> end My_Package;

Apologies in advance for answering a question you didn't ask, but...
any reason not to simply return abs(X-Y)?  If you're thinking that the
result of X-Y will raise a Constraint_Error if it's negative---it
won't.  (At least not in Ada.  I don't know much about SPARK---it
wouldn't raise Constraint_Error there either, would it?)

                                -- Adam



  parent reply	other threads:[~2009-06-19 18:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-19 15:26 SPARK - runtime checks question Maciej Sobczak
2009-06-19 15:31 ` Maciej Sobczak
2009-06-19 16:04 ` Rod Chapman
2009-06-19 18:29   ` Adam Beneschan
2009-06-19 18:55     ` Rod Chapman
2009-06-19 21:38   ` Maciej Sobczak
2009-06-19 18:33 ` Adam Beneschan [this message]
2009-06-19 21:16   ` Maciej Sobczak
replies disabled

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