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,7e29322ee367c19d X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Wrap-Up (was Re: Unchecked_Conversion on different sized types -- problem?) Date: 2000/01/15 Message-ID: #1/1 X-Deja-AN: 572861601 Content-transfer-encoding: 7bit References: Content-Type: text/plain; charset="US-ASCII" X-ELN-Date: Fri Jan 14 20:41:08 2000 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 947911268 38.26.192.205 (Fri, 14 Jan 2000 20:41:08 PST) Organization: EarthLink Network, Inc. Mime-version: 1.0 NNTP-Posting-Date: Fri, 14 Jan 2000 20:41:08 PST Newsgroups: comp.lang.ada Date: 2000-01-15T00:00:00+00:00 List-Id: In article , "Mike Silva" wrote: > 4) Enumerations with representation clauses seem to be a little like piggy > banks -- easy to fill, but harder to extract from. Don't bother using rep clauses for enum types. Just use an integer type. > So, my solution is to map an enumeration to an array of strings. Thanks to > all for your comments. Someone showed how to use Unbounded_String for this. There are a couple of other ways: 1) Use static strings: A_String : aliased constant String := "this is a test"; B_String : aliased constant String := "of the emergency"; C_String : aliased constant String := "broadcast systems"; type Index_Subtype is (A, B, C); type String_Access is access constant String; type String_Table is array (Index_Subtype) of String_Access; Table : constant String_Table := (A => A_String'Access, B => B_String'Access, C => C_String'Access); begin ... Table (B).all ... This avoids heap use. 2) You can use "dynamic" strings, which get allocated statically: type Index_Subtype is (A, B, C); type String_Access is access constant String; type String_Table is array (Index_Subtype) of String_Access; Table : constant String_Table := (A => new String'("this is a test"), B => new String'("of the emergency"), C => new String'("broadcast system")); The strings are all static, and because they're designated by a pointer-to-constant string access object, the compilar is smart enough to do the allocation statically. This avoids heap use. Compilar writers: if we use a little function to call the allocator, ie function "+" (S : String) return String_Access is begin return new String'(S); end; Table : constant String_Table := (A => +"this is a test", B => +"of the emergency", C => +"broadcast sytsem"); begin then is the allocation still done statically?