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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,da29ac1b3f986998 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-12-06 07:12:58 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!redstone.interpath.net!ddsw1!panix!news.intercon.com!udel!news.mathworks.com!news.kei.com!bloom-beacon.mit.edu!gatech!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!riehler From: riehler@ajpo.sei.cmu.edu (Richard Riehle) Subject: Re: intermediate results causing constraint errors Message-ID: <1994Dec6.030051.6818@sei.cmu.edu> Sender: netnews@sei.cmu.edu (Netnews) Organization: AdaWorks Softwasre Engineering References: <3bn3l9$pa2@gnat.cs.nyu.edu> Date: Tue, 6 Dec 1994 03:00:51 EST Date: 1994-12-06T03:00:51-05:00 List-Id: In article bobduff@dsd.camb.inmet.com (Bob Duff) writes: >In article <3bn3l9$pa2@gnat.cs.nyu.edu>, Robert Dewar 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