comp.lang.ada
 help / color / mirror / Atom feed
From: matthew_heaney@acm.org (Matthew Heaney)
Subject: Re: problem in changing Discriminants from access type
Date: 1998/05/11
Date: 1998-05-11T00:00:00+00:00	[thread overview]
Message-ID: <matthew_heaney-ya023680001105982117060001@news.ni.net> (raw)
In-Reply-To: 35577DC2.1A8D482B@cacd.rockwell.com


In article <35577DC2.1A8D482B@cacd.rockwell.com>, aalowe@cacd.rockwell.com
wrote:

(start of quote)
Did the compiler tell which line would cause the constraint error?  On the first
declaration of the discriminant you have start at 1 and end at 0 resulting in
(1..0) which is definiatly a constraint error.
(end of quote)

No.  The index range 1 .. 0 designates a null range, and so the array
object is null.

The rule was carefully designed to *prevent* Constraint_Errors.  The rule
is that, for a null range, you're allowed to violate the constraints of the
subtype (though not of the base type).  For example, 

1 .. 0

-1001 .. -1002

1002 .. 1001  

are all legal index ranges.  Note that the latter two ranges aren't even in
the Int_Limits subtype.  This is perfectly legal, and will NOT raise CE.

That's why you can say

S : String (1 .. 0);

even though 0 is outside the index subtype of type String (Positive).  It's
the reason why

S : String (-1 .. -527);

is legal too, and won't raise CE.

This rule is designed so you won't have to litter your code with special
tests for a null slice.




  reply	other threads:[~1998-05-11  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-05-12  0:00 problem in changing Discriminants from access type Gil Kaspi
1998-05-11  0:00 ` Matthew Heaney
1998-05-11  0:00 ` Lowe Anthony A
1998-05-11  0:00   ` Matthew Heaney [this message]
1998-05-12  0:00 ` Anonymous
replies disabled

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