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,FREEMAIL_FROM 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 Path: g2news1.google.com!postnews.google.com!k2g2000hse.googlegroups.com!not-for-mail From: "=?ISO-8859-1?Q?Egil_H=F8vik?=" Newsgroups: comp.lang.ada Subject: Re: Generic Zero Length Array Date: Fri, 22 Feb 2008 05:53:19 -0800 (PST) Organization: http://groups.google.com Message-ID: <2446841a-8bb0-46bc-94ed-099e4e0ca74c@k2g2000hse.googlegroups.com> References: <9b771018-fb0b-42eb-ae00-12ee3eda69b2@p43g2000hsc.googlegroups.com> NNTP-Posting-Host: 193.71.180.107 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1203688399 9605 127.0.0.1 (22 Feb 2008 13:53:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 22 Feb 2008 13:53:19 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k2g2000hse.googlegroups.com; posting-host=193.71.180.107; posting-account=P68zsgoAAABKpXKMUuwuUZ_RfBk1kZfB User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:19969 Date: 2008-02-22T05:53:19-08:00 List-Id: On Feb 22, 2:31=A0pm, shaunpatter...@gmail.com wrote: > I have a bit of legacy code in my system that I am trying to remove > all warnings from. > > The package is a generic -- with: > > type Element is (<>); > type Element_List is array (Indexing range <>) of Element; > > I have been stumped by one compiler warning where one of the functions > needs to return a zero-length empty generic array: > > warning: variable Result_String is read but never assigned > > code: > > if Error_Condition then > =A0 declare > =A0 =A0 type Result is new Element_List (Indexing.First + 1 .. > Indexing'First); > =A0 =A0 Result_String : Result; > =A0 begin > =A0 =A0 =A0return Element_List (Result); > =A0 end; > end if; > > How do I initialize this array when I can't know what type it is or > will be? > > Thanks > > -- > Shaun A new generic parameter Null_Element would do the trick, but that means changing code wherever the generic is used... type Element is (<>); type Element_List is array (Indexing range <>) of Element; Null_Element : Element; then you could rewrite the above code to if Error_Condition then return Element_List'(Indexing'First..Indexing'First-1 =3D> Null_Element); end if; -- ~egilhh