comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey Creem" <jeff@thecreems.com>
Subject: Re: Test for > 'last
Date: Fri, 14 Mar 2003 12:24:28 GMT
Date: 2003-03-14T12:24:28+00:00	[thread overview]
Message-ID: <0Sjca.93610$sf5.60661@rwcrnsc52.ops.asp.att.net> (raw)
In-Reply-To: 1b585154.0303140406.124c3312@posting.google.com

Someplace between mostly wrong and grossly wrong but likely to be just
optimized away.
(Unless enum_input is a variable of a base type that enum_type is a subtype
of in which case this could
be valid...but I doubt it).

In any case, in Ada 83, there was no 'valid so people were often temped to
write stuff like this..Note that
if data got into enum_input via something like text_io.enumeration_io then
this is incorrect but totally harmless code.

If it got there via some unchecked_conversion or similar approach and there
are not already other reasons
why the data must be valid, then this is not sufficient to detect bad input.


Note that just because it is technically wrong does not mean that if this
code were run with checks suppressed that it would not accomplish what was
desired....It is just that if it did accomplish what was desired, it is only
due to relying on behaviour that is not required by the LRM.




13.9.1 Data Validity

                Bounded (Run-Time) Errors

If the representation of a scalar object does not represent a value of the
object's subtype (perhaps because the object was not initialized), the
object is said to have an invalid representation. It is a bounded error to
evaluate the value of such an object. If the error is detected, either
Constraint_Error or Program_Error is raised. Otherwise, execution continues
using the invalid representation. The rules of the language outside this
subclause assume that all objects have valid representations. The semantics
of operations on invalid representations are as follows:

If the representation of the object represents a value of the object's type,
the value of the type is used.

If the representation of the object does not represent a value of the
object's type, the semantics of operations on such representations is
implementation-defined, but does not by itself lead to erroneous or
unpredictable execution, or to other objects becoming abnormal.

"Peter Richtmyer" <prichtmyer@yahoo.com> wrote in message
news:1b585154.0303140406.124c3312@posting.google.com...
> This may be trivial, but I have come across some code
> in a (weapon control) system that does checks similar
> to:
>
>     ---------------------------------------
>     if enum_input < enum_type'first or
>        enum_input > enum_type'last then
>        -- handle the input error
>     ---------------------------------------
>





  reply	other threads:[~2003-03-14 12:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-14 12:06 Test for > 'last Peter Richtmyer
2003-03-14 12:24 ` Jeffrey Creem [this message]
2003-03-14 17:22 ` Ant
2003-03-14 18:10   ` Vinzent Hoefler
2003-03-17 11:28     ` Ant
2003-03-15  2:02 ` Jeffrey Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox