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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2f343e3986ead102 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!news.motzarella.org!motzarella.org!not-for-mail From: =?ISO-8859-1?Q?S=E9bastien?= Newsgroups: comp.lang.ada Subject: Re: String declaration and initialization Date: Thu, 22 May 2008 16:58:51 +0000 Organization: A noiseless patient Spider Message-ID: References: <05bce551-cd98-417c-8664-847b29124c19@l64g2000hse.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: feeder.motzarella.org U2FsdGVkX1/fUCEgfjOd4ctvhkcAB4wG4ZTmp5EagbGtJIyxDQa/MGFvJ5c2dU2Ka4aM7Ori4O5zEVi1zhu5GHxniZYvFrcoxEo6vj82DyEMc6e2QQwIldc31poyKGritAL6xG3S+TlbkslMa1/yGQ== X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Thu, 22 May 2008 16:58:58 +0000 (UTC) In-Reply-To: X-Auth-Sender: U2FsdGVkX18B0LACTsfZSx7Jis1aVq1wlHJl+H/4yTs1yF07iHrvaQ== Cancel-Lock: sha1:RHjtWw5bAS+gm0OoMM7q+URLXk8= User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) Xref: g2news1.google.com comp.lang.ada:291 Date: 2008-05-22T16:58:51+00:00 List-Id: > The simplest way is to use a bounded or unbounded string: > > declare > S : Unbounded_String; > begin > case Some_Test is > when T1 => S := To_Unbounded_String ("test1"); > ... > end; Yep I think about it but in this case, I made several conversions because I have stuff like that: buffer := To_Unbouned_String(Trim(Integer'Image(my_int), Left)); And then treatment use String so: MyTreatment(To_String(buffer)); So I don't actually know how fast is the conversion between String and Unbounded_String but I think it's a waste of ressource. > Another way is to use a table like you can in C: > > declare > Test1 : aliased constant String := "test1"; > Test2 : aliased constant String := "test2"; > > type Table_Type is array (Test_Type) of > not null access constant String; > > Table : constant Table_Type := > (T1 => Test1'Access, > T2 => Test2'Access, > ...); > > S : String renames Table (Some_Test).all; > begin > ... > end; That's an idea but... Test1 are actually not a constant string, that was an example :-) It's calculated sometime it's even a return of some function and so on. But you give me an Idea : declare buffer: access String; Free_String is new Unchecked_Deallocation(String, access all String); begin case SomeTest is case TEST1 => buffer := new String("Test1"); case TEST2 => buffer := new String("Test2"); end case; MyTreatment1(buffer.all, buffer.all'Size); MyTreatment2(buffer.all, buffer.all'Size); MyTreatment3(buffer.all, buffer.all'Size); end; but it doesn't work of course since I can't create with new an unconstrained object.