comp.lang.ada
 help / color / mirror / Atom feed
From: Theodore Dennison <dennison@escmail.orl.mmc.com>
To: edward@igate1.hac.com
Subject: Re: Optimizing and Constraint Checks
Date: 24 Mar 1995 13:34:48 GMT
Date: 1995-03-24T13:34:48+00:00	[thread overview]
Message-ID: <3kuhpo$ban@theopolis.orl.mmc.com> (raw)
In-Reply-To: edward-2303951004270001@r-618macip27.hac.com

Ed Bruce <edward@igate1.hac.com> writes:

> I am currently attempting to implement a safe, portable
> Unchecked_Conversion of an enumerated type to integer and from an integer
> type back to the enumeration. The following code shows the current
> solution, the question raised by one engineer is can we guarantee the the
> return statement in the To_Enum function is portable. That is may a
> compiler optimize away the ENUM'Pos and ENUM'Val and effectively eliminate
> the constraint check.


Your engineer has a vaild concern. One of the problems with Ada 83 is that 
there is no PORTABLE way to force a constraint check. In practice, you have
to find what your compiler won't optimize away, and code to that. 
Unfortunately, the next version of the same compiler could work differently.

In practice this isn't as big a problem as it looks on paper. I have only 
encountered one compiler (for an embedded system) which optimized away too
many checks. The benefits that this kind of type checking can give you 
vastly outweigh the problems it causes. Just make sure you test it!

Hopefully, this problem was fixed with Ada 95.

T.E.D.




  reply	other threads:[~1995-03-24 13:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-03-23 16:04 Optimizing and Constraint Checks Ed Bruce
1995-03-24 13:34 ` Theodore Dennison [this message]
1995-03-25 18:09   ` David Wheeler
1995-03-29  0:00   ` Ed Bruce
1995-03-24 20:15 ` Garlington KE
1995-03-26 12:01   ` Robert Dewar
1995-03-27 16:58     ` Garlington KE
1995-03-29  0:00     ` Ed Bruce
1995-03-29  0:00       ` Garlington KE
1995-03-30  0:00       ` Mike Meier
1995-04-04  0:00       ` Robert Dewar
1995-03-25 17:51 ` 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