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 Path: g2news1.google.com!news1.google.com!postnews.google.com!e6g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Generic Zero Length Array Date: Fri, 22 Feb 2008 15:01:02 -0800 (PST) Organization: http://groups.google.com Message-ID: <7cd05c2a-d67a-4623-a9dc-67e357877f48@e6g2000prf.googlegroups.com> References: <9b771018-fb0b-42eb-ae00-12ee3eda69b2@p43g2000hsc.googlegroups.com> <2446841a-8bb0-46bc-94ed-099e4e0ca74c@k2g2000hse.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1203721262 17463 127.0.0.1 (22 Feb 2008 23:01:02 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 22 Feb 2008 23:01:02 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: e6g2000prf.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:20000 Date: 2008-02-22T15:01:02-08:00 List-Id: On Feb 22, 11:25 am, "Randy Brukardt" wrote: > "Egil H=F8vik" wrote in message > > news:2446841a-8bb0-46bc-94ed-099e4e0ca74c@k2g2000hse.googlegroups.com... > > > > >On Feb 22, 2:31 pm, 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: > ... > >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; > > If you are not limited to Ada 95, you can use the <> here, and then you > don't need the extra generic parameter: > > if Error_Condition then > return Element_List'(Indexing'First..Indexing'First-1 =3D> <>); > end if; Drat, I wish I'd thought of that. Yes, this seems best. Way back before Ada 95, someone made a proposed language array to add a "null array" aggregate to the language, so that you could write an aggregate to represent a zero-element array without needing a fake value for the elements. I thought this was a great idea and could never understand why it wasn't adopted. It would have solved the problem here. But the <> syntax of Ada 2005 obviates the need for something like that. I don't think we need "null record" (i.e. in aggregates) any more either, although certainly nobody is going to suggest removing it. [Actually, there's one case where you still can't specify a null array aggregate, and that's where the index type is either "mod 1" or an enumeration type with one value: type Enum is (This_One); type Arr is array (Enum range <>) of Anything; Now go ahead and try to specify a zero-element array aggregate of type Arr. You can't. But this is a pretty pathological case so it's not worth trying to change the language for it.] -- Adam