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-05 19:12:40 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!ix.netcom.com!netcomsv!netcomsv!telesoft!kst From: kst@alsys.com (Keith Thompson) Subject: Re: intermediate results causing constraint errors Message-ID: Originator: kst@pulsar Sender: news@alsys.com (USENET News Admin @flash) Organization: Alsys, San Diego, CA, USA References: <3bn3l9$pa2@gnat.cs.nyu.edu> Date: Tue, 6 Dec 1994 00:50:53 GMT Date: 1994-12-06T00:50:53+00:00 List-Id: In bobduff@dsd.camb.inmet.com (Bob Duff) writes: > 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. > > 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). Actually, you're likely to find out when you try to port the code from an implementation that derived T from a predefined 32-bit type to one that derives it from a predefined 16-bit type. Ada 83 specifies that a user-defined integer type is derived from a predefined integer type "implicitly selected by the implementation" so as to include the declared bounds; it doesn't specify exactly how the parent type is selected. I know of at least one implementation that derives T from Integer (32 bits), and another that derives it from Short_Integer (16 bits); both implementations have 32-bit Integer and 16-bit Short_Integer. The behavior can also depend on whether the intermediate result is stored in a register (typically 32 bits) or in a memory object (typically the size of type T). -- Keith Thompson (The_Other_Keith) kst@alsys.com TeleSoft^H^H^H^H^H^H^H^H Alsys, Inc. 10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718 /user/kst/.signature: I/O error (core dumped)