comp.lang.ada
 help / color / mirror / Atom feed
From: kst@alsys.com (Keith Thompson)
Subject: Re: intermediate results causing constraint errors
Date: Tue, 6 Dec 1994 00:50:53 GMT
Date: 1994-12-06T00:50:53+00:00	[thread overview]
Message-ID: <D0D6Cu.Ir4@alsys.com> (raw)
In-Reply-To: D0Cp98.1AK@inmet.camb.inmet.com

In <D0Cp98.1AK@inmet.camb.inmet.com> 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)



  parent reply	other threads:[~1994-12-06  0:50 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 [this message]
1994-12-06  8:00   ` Richard Riehle
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