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!news3.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Generic Zero Length Array Date: Fri, 22 Feb 2008 09:26:38 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <9b771018-fb0b-42eb-ae00-12ee3eda69b2@p43g2000hsc.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1203690398 26892 192.74.137.71 (22 Feb 2008 14:26:38 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 22 Feb 2008 14:26:38 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:u4NqhDgPUtL/zR/u2tvo66DoDjQ= Xref: g2news1.google.com comp.lang.ada:19973 Date: 2008-02-22T09:26:38-05:00 List-Id: shaunpatterson@gmail.com writes: > 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 If the warning is wrong, the appropriate thing to do is pragma Warnings(Off, ...). See the docs for various useful options. Also look at pragma Unreferenced, which might be appropriate in other cases. > code: > > if Error_Condition then > declare > type Result is new Element_List (Indexing.First + 1 .. > Indexing'First); > Result_String : Result; > begin > return Element_List (Result); > end; > end if; You've got some typos there -- better to cut&paste the exact code. I can't tell for sure without more context, but that code looks strange. Why declare a new type? Why not: subtype Result is Element_List (...); Result_String : Result; ... return Result_String; Or: Result_String : Element_List (...); ... return Result_String; Or (in Ada 2005): return Element_List'(Indexing'Base'First+1 .. Indexing'Base'First => <>); And it wouldn't hurt to put: pragma Assert (Indexing'Base'First < Indexing'Base'Last); in the package spec, since this generic won't work with a one-element or zero-element base type. > How do I initialize this array when I can't know what type it is or > will be? You don't have to initialize it. But if you want to, an aggregate will work. - Bob