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!feeder.erje.net!eu.feeder.erje.net!news.swapon.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 19:30:32 +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 Fvlxwrq6mqYzPHc33lmQqQpsjGuDvyeauOVun7LcU/ICukWGms Cancel-Lock: sha1:WmtTWvrh636tm9YG0YfzV/J3g6E= 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:18401 Date: 2014-02-06T19:30:32+02:00 List-Id: On 14-02-06 18:13 , Gerd wrote: > type Memory_Block (len : Natural) is > record > Start_Address : Mem_Addr; > Block_Size : Natural; > Usage_Info : Mem_Array (0..len-1); > end record; > > the compiler tells me that this is not allowed. > > Is it possible to allocate "len" units, but address them from 0 .. len - 1? > > How can I do this? This restriction sometimes annoys me too. You can pass a record discriminant to a component, but you cannot alter it in any way, such as by adding or subtracting something. So the only possibility is to change the meaning of the discriminant to be "len - 1": type Memory_Block (last : Natural) is record Start_Address : Mem_Addr; Block_Size : Natural; Usage_Info : Mem_Array (0..last); end record; (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.) -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .