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: 103376,ace9bff8eb84e5b1 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!d21g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Generic Zero Length Array Date: Fri, 22 Feb 2008 08:52:39 -0800 (PST) Organization: http://groups.google.com Message-ID: <4c024f41-3ff8-4d70-ac6c-551f129289a1@d21g2000prf.googlegroups.com> References: <9b771018-fb0b-42eb-ae00-12ee3eda69b2@p43g2000hsc.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1203699159 1278 127.0.0.1 (22 Feb 2008 16:52:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 22 Feb 2008 16:52:39 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d21g2000prf.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:19978 Date: 2008-02-22T08:52:39-08:00 List-Id: On Feb 22, 6:23 am, Stefan Lucks wrote: > On Fri, 22 Feb 2008, shaunpatter...@gmail.com wrote: > > How do I initialize this array when I can't know what type it is or > > will be? > > if Error_Condition then > > declare > > type Result is new Element_List (Indexing.First + 1 .. > > Indexing'First); > > Result_String : Result; > > Result_String : Result := (others => Some_Default_Value); > > > begin > > return Element_List (Result); > > end; > > end if; > > This should work. The default value doesn't matter at all, because the > array is empty. But you still need to know a default value of the > appropriate type. If the *only* use of this default value would be to use it as an initializer for an array that we know is going to be empty, so that the default value is never used, I don't think I'd recommend this solution. It may work to get rid of the warnings, but it seems like a poor design idea to require a parameter that is never used. I think one of Bob's solutions is preferable, if it's really necessary to get rid of the warnings. This is simply a case where you know more than the compiler. However, in a case where you do need to initialize something of a generic formal type, adding an "initial value" generic parameter is the way to do it. -- Adam