comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: My bug or else regarding Visibility Rules
Date: Thu, 04 Apr 2013 20:47:47 +0100
Date: 2013-04-04T20:47:47+01:00	[thread overview]
Message-ID: <ly7gkigjrw.fsf@pushface.org> (raw)
In-Reply-To: 282c7f39-f77e-416c-81f8-1f8fb5ad6d0a@googlegroups.com

Anh Vo <anhvofrcaus@gmail.com> writes:

> On Thursday, April 4, 2013 1:19:54 AM UTC-7, Simon Wright wrote:
>> Anh Vo <anhvofrcaus@gmail.com> writes: > On Tuesday, April 2, 2013
>> 1:16:34 PM UTC-7, Simon Wright wrote:

>>> I do not understand this. Why isn't Buffer(1) valid if my index
>>> starts at 1?
>
>> Because after the index has wrapped round Buffer'Old(1) will not be the 
>> same as Buffer(1). 
>
> In this case the loop will drop out because loop lower end is greater
> than loop upper end.

Consider a queue of max length 5 containing letters. 5 letters (a, b, c,
d, e) have been Put, and one (a) Got.

   I
   a b c d e
     O

After the next letter is inserted, you'd have

     I
   f b c d e
     O

Your check is

   (for all I in 1 .. Queue_Length'Old =>
                 Buffer(I) = Buffer'Old (I))

which is going to fail.

>> No. You wrote 
>>   (Index mod Length) + 1 
>> but it should be 
>>   (Index + 1) mod Length 
>
> (In_Index + 1) mod length will raise Constraint_Error when the Queue
> is just full. In fact, (10 + 1) > 10 when the queue has the lenght of
> 10.

OK, I've never seen this way of managing an index but I can see it
working. Still think that 0-based is easier.

That said, (In_Index + 1) won't raise CE, because Index is a subtype and
inherits the operations of Integer. CE on assignment, sure, but the 'mod
Length' would have been applied by then.



  reply	other threads:[~2013-04-04 19:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-28 19:54 My bug or else regarding Visibility Rules Anh Vo
2013-03-28 20:58 ` Adam Beneschan
2013-03-28 22:03   ` Randy Brukardt
2013-03-30  6:05     ` Anh Vo
2013-04-02  0:56       ` Randy Brukardt
2013-04-02  1:52         ` Anh Vo
2013-04-02  8:26           ` Simon Wright
2013-04-02 18:17             ` Anh Vo
2013-04-02 20:16               ` Simon Wright
2013-04-03 23:21                 ` Anh Vo
2013-04-04  8:19                   ` Simon Wright
2013-04-04 19:21                     ` Anh Vo
2013-04-04 19:47                       ` Simon Wright [this message]
2013-04-02 22:04           ` Randy Brukardt
2013-03-28 22:06   ` Anh Vo
replies disabled

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