From: kst@aonix.com (Keith Thompson)
Subject: Re: Ada 83 - avoiding unchecked conversions.
Date: 1996/12/19
Date: 1996-12-19T00:00:00+00:00 [thread overview]
Message-ID: <E2ooC4.FMy@thomsoft.com> (raw)
In-Reply-To: dewar.850929268@merv
In <dewar.850929268@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
[...]
> Note that the unchecked in unchecked conversion is talking about omitting
> normal compile time checks for type correctness. It is NOT talking about
> runtime checking (whatever that might mean). In general you cannot assume
> that unchecked conversion takes no code. Some of the time it may take
> no code, but there is no reason to think, or even considerable desirable,
> that a compiler would never generate code for an unchecked conversion.
Certainly unchecked conversion can require some code in some cases, but
one wouldn't normally expect that code to include constraint checks.
> Sometimes you would get the wrong result in the absence of generating
> code. For example, suppose that packed 5 bit arrays were stored left
> justified in a register, and 5 bit integers were stored right justified.
> Well the compiler had beetter emit a shift for the unchecked conversion
> or it will get the wrong result (remembr that the semantics of
> unchecked conversion is quite well defined, it is not some kind of
> implementation dependent unknown op0eration).
I agree that the compiler needs to emit a shift for this case, but
it shouldn't generate a check that the result is within the declared
range of its subtype. This makes it the programmer's responsibility to
guarantee that the result will be a valid value of the target subtype
(if possible, by using a target subtype that covers all possible bit
patterns), or to deal with it properly if it isn't.
On the other hand, if the result of a unchecked conversion is assigned
to an object, there may well be a constraint check on the assignment.
--
Keith Thompson (The_Other_Keith) kst@aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706
"SPOON!" -- The Tick
next prev parent reply other threads:[~1996-12-19 0:00 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <md5:8B831999BCF200C6E70994BDF6CC529F>
1996-12-11 0:00 ` Ada 83 - avoiding unchecked conversions Chris Sparks (Mr. Ada)
1996-12-11 0:00 ` Matthew Heaney
1996-12-12 0:00 ` Chris Brand
1996-12-13 0:00 ` Stephen Leake
1996-12-14 0:00 ` Robert A Duff
1996-12-14 0:00 ` BGaffney42
1996-12-11 0:00 ` Dewi Daniels
1996-12-12 0:00 ` Richard Kenner
1996-12-17 0:00 ` Eric Miller
1996-12-18 0:00 ` Robert Dewar
1996-12-18 0:00 ` Robert A Duff
1996-12-19 0:00 ` Keith Thompson [this message]
1996-12-26 0:00 ` Robert Dewar
1996-12-19 0:00 ` Robert I. Eachus
1996-11-27 0:00 Ensco Vendor
1996-11-27 0:00 ` Robert I. Eachus
1996-11-29 0:00 ` Robert Dewar
1996-12-01 0:00 ` Darel Cullen
1996-11-30 0:00 ` Robert Dewar
1996-12-11 0:00 ` Richard Riehle
1996-12-02 0:00 ` Ted Dennison
1996-12-10 0:00 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox