comp.lang.ada
 help / color / mirror / Atom feed
From: kdm@puppy.rational.com (Kent Mitchell)
Subject: Re: Range Check Query
Date: 23 Nov 1994 17:31:32 GMT
Date: 1994-11-23T17:31:32+00:00	[thread overview]
Message-ID: <3avu9k$t02@rational.rational.com> (raw)
In-Reply-To: 9411181527.AA08827@eurocontrol.de

Bob Wells #402 (wel@EUROCONTROL.DE) wrote:
:   type dn18906 is  -- layout is for the 18906 message  .
:     record
:       dnspare  : integer range 0 .. 1;
:       dnspare2 : integer range 0 .. 3;
:       dnch1    : integer range 0 .. (2**7) - 1;
:       dnch2    : integer range 0 .. (2**7) - 1;
:     end record;

:    for dn18906 use
:      record at mod 1;
:        dnspare at 0 range 0 .. 1;
:        dnspare2 at 0 range 2 .. 7;
:        dnch1 at 0 range 8 .. 15;
:        dnch2 at 0 range 16 .. 23;
:      end record;

:    for dn18906'size use 24;

:    type Dn_189_Data is array(1 .. N_Data) of Dn18906;
:    pragma Pack(Dn_189_Data);

:    M_T : Dn_189_Data;
:    for M_T use at P_Mesg_Conv(P_Ohead) + 12;

: P_Mesg_Conv is an Unchecked_Conversion of an access type to a
: system address. The access type points to an incoming byte
: stream.

: OK, then in the body of this package we have:


:    if M_T(1).Dnspare = 2 then

: --     do something

:    end if;

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

: Once again we are using the

: Verdix Ada Compiler, Copyright 1984, 1992
: VADSworks for Sun-4 -> MC68020/30/vxWorks, (VADS 6.0.5)
: Mon Aug 17 09:11:00 EST 1992 2.0.3(b)

Hmmm ... this is an interesting program from a number of aspects.  I don't
think you'd get a constraint error because there never is a checked
assignment.  You will not get a range check from unchecked_conversion nor
will you get a range check on the boolean expression (because it's not an
assignment).  

The second interesting problem is that I'd never expect the true arm of the
if to be taken as the compiler should have supressed this as dead code (of
course that depends on the optomization level).  I do see how it "could"
take the arm if it's not supressed because the code *does* allocate 2 bits
for the Dnspare field so a value of 2 *is* possible.

To sum this all up, given a basically eronious program, anything is
possible.

--
Kent Mitchell                   | One possible reason that things aren't
Technical Consultant            | going according to plan is .....
Rational Software Corporation   | that there never *was* a plan!



      parent reply	other threads:[~1994-11-23 17:31 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
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 [this message]
replies disabled

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