From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!goblin3!goblin.stu.neva.ru!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Need help for constrained type Date: Thu, 06 Feb 2014 20:37:30 +0200 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: individual.net uj7U3wgrHlKttRYMeH3/UgrDGKSh63zygbh5yjq5AP0k84QtFc Cancel-Lock: sha1:2ACm7ajLB2qwsjQczgg58N6nAik= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:18404 Date: 2014-02-06T20:37:30+02:00 List-Id: On 14-02-06 20:03 , adambeneschan@gmail.com wrote: > On Thursday, February 6, 2014 9:30:32 AM UTC-8, Niklas Holsti wrote: > >> (If you want to allow an empty Usage_Info, indexed 0..-1 for >> example, you must of course declare Memory_Block.last using some >> range which includes negative numbers, for example Integer.) > > That actually isn't true. It is here, I think, because the upper bound comes from a discriminant, where subtypes are checked more strictly. And the lower bound is fixed to zero, so only a negative upper bound makes an empty range. > The bounds of an empty range do *not* need > to be within the subrange. Here, Natural is a subrange 0 .. > Integer'Last, but Integer is the base type, and as long as the bounds > belong to the base type, it's OK. Agreed. But if I have type Memory_Block (last : Natural) is record ... Usage_Info : Mem_Array (0..last); end record; then I'm pretty sure that the declaration M : Memory_Block (last => -1); will be rejected, because -1 is not in Natural. GNAT says: mb.adb:15:30: warning: static value out of range of type "Standard.Natural" mb.adb:15:30: warning: "Constraint_Error" will be raised at run time -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .