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!feeder.eternal-september.org!news.uzoreto.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!2001:888:0:311::2f.MISMATCH!nzpost2.xs4all.net!news.kpn.nl!not-for-mail Subject: Re: Anonymous array not allowed as components To: joakimds@kth.se Newsgroups: comp.lang.ada References: <5dbbeda6$0$1458$e4fe514c@news.kpn.nl> <1a0b573e-11af-4e4c-9ccf-9a757ad8d970@googlegroups.com> From: L Dries Message-ID: Date: Fri, 1 Nov 2019 11:00:21 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 In-Reply-To: <1a0b573e-11af-4e4c-9ccf-9a757ad8d970@googlegroups.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: nl Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 97dbad92.news.kpn.nl X-Trace: G=ANiePiJO,C=U2FsdGVkX19fyfDohhV70D19VGUFQKPpcQkmhSSzsZqnqxQTsgfZuuG76H4VW2PQF3y11YKQra7o8C59RzWaz5NUWpDTU+y1CwwqVpL8ZKE= X-Complaints-To: abuse@kpn.nl Xref: reader01.eternal-september.org comp.lang.ada:57414 Date: 2019-11-01T11:00:21+01:00 List-Id: Op 1-11-2019 om 10:34 schreef joakimds@kth.se: > Den fredag 1 november 2019 kl. 09:32:42 UTC+1 skrev L Dries: >> I have an need for an array of Unbounded_Strings in which i define the >> elements. >> >> I declared it as: >> >> Debug_Proc : array (1 .. nr_Proc) of Unbounded_String := >> (Debug_Proc(Lan), >> To_Unbounded_String("Only"), >> To_Unbounded_String("Empty_Buffer"), >> ... >> etc. >> >> Then I got the message: >> >> 65:22 Anonymous array not allowed as components >> This results i a position just before "array" >> >> The value nr_Proc is defined in another package. >> Debug_Proc(Lan) is an Unbounded String >> I tried to replace nr_Proc by a value. The same result. >> I tried to replave the value of the first Unbounded String by "--", >> again no result >> I tried set it as an constant array, also no result. >> >> What do I do wrong? >> -- >> L. Dries > > Hello L. Dries, > > Unbounded_String is well-known for being "slow" because it does unnecessary heap-allocations. To avoid performance penalty the XString type has been defined in the GNATColl library. The point is that one should have very good reasons to use Unbound_String in one's application and not use it needlessly. > > In your case what you want is to map each integer in an interval to a specific String. If that's the case I recommend taking advantage of expression functions and case statements introduced in Ada 2012: > > type Index is new Integer range 1 .. nr_Proc; > > function Debug_Proc (I : Index) return String is > (case I is > when 1 => "Only", > when 2 => "Empty_Buffer", ...); > > or maybe it is: > > function Debug_Proc (I : Index) return String is > ((case I is > when 1 => "Only", > when 2 => "Empty_Buffer", ...)); > > The compiler will tell you. > > Best regards, > Joakim > I will look nto that possibility, but for this project it is too late because changing would mean almost completely rewriting the program. -- L. Dries