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!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: How can I create an empty array of a generic type? Date: Sun, 14 Jul 2019 13:27:54 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <5f53e122-6b99-48ca-b6cc-4ae43c0a2221@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 14 Jul 2019 11:27:54 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="cba3e20503323fa77641c7f1b7e4fc80"; logging-data="6248"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PyEH7+dUzG7W/VKWfD2QAzl3pWBnObEk=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 Cancel-Lock: sha1:CeLLGfvEdbzd/a3GmZ4xpa2qZFc= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:56872 Date: 2019-07-14T13:27:54+02:00 List-Id: On 7/14/19 1:15 PM, reinert wrote: > lørdag 13. juli 2019 07.24.10 UTC+2 skrev J-P. Rosen følgende: > ..... >> You can avoid it: >> Empty_Key : constant Key_Type(1..0) := (others => <>); >> > > But Key_Type is an array indexed by Positive (> 0). > The zero in "Key_Type(1..0)" is not so intuitive for me (outside the range) ? Try this: with Ada.Text_IO; procedure Null_Last is S : constant String := ""; begin -- Null_Last Ada.Text_IO.Put_Line (Item => Integer'Image (S'Last) ); end Null_Last; See also ARM 3.5: (4) "A range with lower bound L and upper bound R is described by “L .. R”. If R is less than L, then the range is a null range, and specifies an empty set of values." (8) "A range is compatible with a scalar subtype if and only if it is either a null range or each bound of the range belongs to the range of the subtype." So 1 .. 0 is a null range. A null range is compatible with any scalar subtype, so it is compatible with Positive. -- Jeff Carter "I have a very small head and I had better learn to live with it ..." Edsger Dijkstra 158