comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Range Check Query
Date: 18 Nov 94 12:11:26
Date: 1994-11-18T12:11:26+00:00	[thread overview]
Message-ID: <EACHUS.94Nov18121126@spectre.mitre.org> (raw)
In-Reply-To: Bob Wells #402's message of Fri, 18 Nov 1994 16:27:49 +0100

In article <9411181527.AA08827@eurocontrol.de> Bob Wells #402 <wel@EUROCONTROL.DE> writes:

 > Why does the following not raise a Constraint_Error exception?
 > (It doesn't even raise a compile time warning)

  You really have two different questions.  First

      if M_T(1).Dnspare = 2 then

  Why doesn't the compiler complain about this?  Why should it?  The
expression on the left is of TYPE Integer, and 2 is certainly
convertable to a value of TYPE Integer, and is in the range of
Integer.  The compiler is allowed to be smart and optimize this to
False.  (If it is that smart it should probably warn you of the fact
that it does so.  But I suspect it is smart enough to notice that
there are no guarentees on the value of Dnspare...)

   Second:

 > The incoming stream definitely has value of 2 occaisionaly in this
 > component yet it doesn't raise Constraint_Error?

     Your program is literally erroneous.  If the compiler was smart
enough to figure this out the "right" exception is PROGRAM_ERROR, but
anything the compiler does at this point is legal.  You have created
an illegal value in M_T(1), then read it, and you expect the compiler
to do something other than throw up its hands at this point?

     The ARG has been back and forth about this and other similar
cases.  The "best" thing to do in this case is to define a record type
in the read procedure which covers all possible values, and do
explicit range checking on that.  (The value returned can be converted
to the type with meaningful ranges.)

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...



  reply	other threads:[~1994-11-18 12:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-11-18 15:27 Range Check Query Bob Wells #402
1994-11-18 12:11 ` Robert I. Eachus [this message]
1994-11-19 16:58   ` Robert Dewar
1994-11-21 10:57     ` Robert I. Eachus
1994-11-20 17:16 ` Do-While Jones
1994-11-21 16:00 ` Norman H. Cohen
1994-11-23 17:31 ` Kent Mitchell
replies disabled

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