comp.lang.ada
 help / color / mirror / Atom feed
From: riehler@ajpo.sei.cmu.edu (Richard Riehle)
Subject: Re: intermediate results causing constraint errors
Date: Tue, 6 Dec 1994 03:00:51 EST
Date: 1994-12-06T03:00:51-05:00	[thread overview]
Message-ID: <1994Dec6.030051.6818@sei.cmu.edu> (raw)
In-Reply-To: D0Cp98.1AK@inmet.camb.inmet.com

In article <D0Cp98.1AK@inmet.camb.inmet.com> bobduff@dsd.camb.inmet.com (Bob Duff) writes:
>In article <3bn3l9$pa2@gnat.cs.nyu.edu>, Robert Dewar <dewar@cs.nyu.edu> wrote:
>>Richard Riehl worries about "constraint errors in intermediate results
>>in expressions of mixed type"
>>
>>What's *that* about?
>>
>>Ada gives you complete control over the type of all intermediate results,
>
>Robert,
>
>I didn't see Richard Riehl's comment, but I don't understand your point.
>If I write:
>
>    type T is range 1..10_000;
>    X: T := 10_000;
>    Five: T := 5;
>    Ten: T := 10;
>    ...
>    X := (X * Five) / Ten;
>
>one implementation might overflow on the multiply and another might not.

   In fact, the Mil-Std 1815 ALRM explicitly alllows for this variation 
   in implementation by requiring Numeric_Error (not Constraint_Error)
   when run-time errors occur due to problems during evaluation of 
   intermediate expressions.  Check out the wording of ALRM 11.6 / 6.

    Richard Riehle 

>
>It's true that there are ways to avoid this (define a wider-ranged type
>first, and define T as a subtype of that), but I would say that that
>requires some "Ada experience".  Furthermore, the Ada compiler won't
>necessarily tell you about the problem, either at compiler or run-time
>-- you'll find out when you try to port the code from a 32-bit machine
>to a 16-bit machine (a rarity these days, I suppose).
    >
    One need not even restrict this  knotty little problem to inter-platform 
    porting.  I have used compilers which require some care in planning
    for this eventuality. 

     R. Riehle

>>and you only get constraint error if you choose the wrong type. It would
>>be wrong for *any* language not to give this kind of control. I simply
>>don't see *any* problem here, and certainly I don't see a problem that
>>needs the expertise of "experienced Ada" programmers to deal with it.
>
    Unfortunately, it is not a language issue.  The ALRM does have something
    to say about it.  But it is not forbidden by the ALRM.  And maybe that
    does make it a language issue.  This is one of those caveat emptor
    issues.  Ignore it at your peril  :-)

    Richard Riehle




  parent reply	other threads:[~1994-12-06  8:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3bn3l9$pa2@gnat.cs.nyu.edu>
1994-12-05 18:41 ` intermediate results causing constraint errors Bob Duff
1994-12-05 19:20   ` Bob Duff
1994-12-06  0:50   ` Keith Thompson
1994-12-06  8:00   ` Richard Riehle [this message]
1994-12-06 13:40   ` Robert Dewar
1994-12-07 17:17     ` Richard Riehle
1994-12-10 13:41       ` Robert Dewar
replies disabled

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