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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,e61e0c2934b7f4d5 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Question on array of strings Date: Thu, 29 Oct 2009 20:12:10 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <562b9c59-5c4e-42d3-b4b9-bfcd33bc3211@j4g2000yqe.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: pcls6.std.com 1256861524 30841 192.74.137.71 (30 Oct 2009 00:12:04 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 30 Oct 2009 00:12:04 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:NP/Kmfalx2UALl5k8x91UeJAFhg= Xref: g2news2.google.com comp.lang.ada:8868 Date: 2009-10-29T20:12:10-04:00 List-Id: In addition to the good answers in this thread, another thing that might work for the OP is: Events_Type'Image(Event) although it annoyingly uses ALL_CAPS, and doesn't work if the event names contain blanks and whatnot. "Hibou57 (Yannick Duch�ne)" writes: > Next now : you have an array of constant, which will be initialized > each times you enter the function. There are no kind of � static � in > Ada like there are in C. To achieve static global allocation, you have > to declare your array outside of the function, at the package level. This part is not necessarily true. The compiler is free to do static global allocation here. > So now, try to change > > function Event_To_String(Event : in Events_Type) return String is > Ev1_Name : aliased constant String :="ev3434"; > Ev2_Name : aliased constant String :="evEnd"; The above strings are certainly statically allocated in GNAT. > eventStrings : constant array (Events_Type) of access constant > String := > (Ev1_Name'Access, > Ev2_Name'Access); I think the above array is, too, but I'm not sure. You'd have to experiment to find out. > begin > return EventStrings(Event).all; > end Event_To_String;begin In other words, a good compiler will do the following tranformation for you. The advantage is to avoid polluting the global namespace. > into > > Ev1_Name : aliased constant String :="ev3434"; > Ev2_Name : aliased constant String :="evEnd"; > > eventStrings : constant array (Events_Type) of access constant > String := > (Ev1_Name'Access, > Ev2_Name'Access); > > function Event_To_String(Event : in Events_Type) return String is > begin > return EventStrings(Event).all; > end Event_To_String;begin - Bob