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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5430b81ad265fc75,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-13 19:00:53 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.xnet.com!dfw-peer!news.verio.net!iad-read.news.verio.net.POSTED!not-for-mail From: Dr Nancy's Sweetie Subject: Array Of Constant Strings? Newsgroups: comp.lang.ada Organization: Rowan University User-Agent: tin/1.4.6-20020816 ("Aerials") (UNIX) (SunOS/5.8 (sun4u)) Message-ID: Date: Fri, 14 Feb 2003 02:58:57 GMT NNTP-Posting-Host: 150.250.64.69 X-Complaints-To: abuse@verio.net X-Trace: iad-read.news.verio.net 1045191537 150.250.64.69 (Fri, 14 Feb 2003 02:58:57 GMT) NNTP-Posting-Date: Fri, 14 Feb 2003 02:58:57 GMT Xref: archiver1.google.com comp.lang.ada:34083 Date: 2003-02-14T02:58:57+00:00 List-Id: Maybe I'm just doing this wrong, but the only solution I can see looks unreasaonbly verbose. What I want is to set up an array of constant strings, all the same length. I tried using Ada.Strings.Bounded, with something like this: package Name_Package is new Generic_Bounded_Length(7); type Name_String is new Digit_Package.Bounded_String; Name_List : constant array(1..26) of Name_String := ("Anthony", "Barbara", "Claudia", "Deborah" "Elliott", .... and so on. But it complains that: expected private type "Name_String" defined at line 26 found a string type (I sorta expected this to work because a similar initialization is possible with Integers.) I can throw in explicit conversion functions: function To_Name_String(Source: String; Drop: Truncation := Right) return Name_String renames Name_Package.To_Bounded_String; and then make the Name_List this way: Name_List : constant array(1..26) of Name_String := (To_Name_String("Anthony"), To_Name_String("Barbara"), To_Name_String("Claudia"), ... and so on. But that seems really klunky, somehow; like there ought to be a better way to do this than repeating "To_Name_String" dozens of times. It won't let me just say: Name_List : constant array(1..26) of String := ("Anthony", "Barbara", "Claudia", "Deborah" "Elliott", .... and so on. because, as it informs me, unconstrained element type in array declaration So is there some better way to do this? I primarily speak C, so I'm used to (and maybe spoiled by 8-) a little type flexibility which isn't here to be had. The strings don't have to be bounded: the input is guaranteed to be exactly a given length, so fixed-length strings would be fine. But I couldn't get that to work either. My situation is that I have a bunch of strings, all the same length, and they'll never ever change. All I want to do is stick them in an array so later I can read in a strings and see if it matches one on my list, and if so in what position. What's the "best" (for some definition of "best") way to do that? Darren Provine ! kilroy@elvis.rowan.edu ! http://www.rowan.edu/~kilroy "Many verbal attacks are part of someone's aim to establish their rank in a dominance hierarchy, the same sort of behavior common among nesting fowl." -- Daniel Mocsny