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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ccb8bd6b4c3162fd X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Beginner's questions Date: 1999/05/04 Message-ID: #1/1 X-Deja-AN: 473782736 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <7gkq7e$dcm$1@nnrp1.dejanews.com> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1999-05-04T00:00:00+00:00 List-Id: dennison@telepath.com wrote: : > 2) I want to use a fixed-size array of constant strings to store some : > names which do not all have the same length, but no name is longer : .. : > is raised. How should I do it? : If you won't need to change the contents of the strings, one quick-and-dirty : method is the following: : type String_Ptr is access String; ^^^ "constant" : type String_Ptr_List is array (1..3) of String_Ptr; : String_List : constant String_Ptr_List := : (new String'("Hi there!"), : new String'("How are you doing?"), : new String'("Why, I'm fine. How are you?") : ); : Don't do this in a loop or subroutine, unless you are prepared to deallocate : the strings when you are done. But as one-time-only code on an OS that cleans : up process resources after termination this often does the trick for me. If you use "type String_Ptr is access constant String" to declare your pointer type, then the language prevents erroneous overwriting of the strings, and the compiler (if it follows the Ada 95 implementation advice) will allocate and initialize the pointed-to strings at link-time, rather than run-time, exactly like "C" string literals. : -- : T.E.D. : -----------== Posted via Deja News, The Discussion Network ==---------- : http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA