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,5af5c381381ac5a7 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!192.87.166.28.MISMATCH!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!feed.xsnews.nl!border-1.ams.xsnews.nl!news.netcologne.de!ramfeed1.netcologne.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 08 Jun 2010 13:35:18 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada requires too much typing! References: <876j8vF54kU1@mid.individual.net> In-Reply-To: <876j8vF54kU1@mid.individual.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4c0e2af7$0$7659$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 08 Jun 2010 13:35:19 CEST NNTP-Posting-Host: c386cff6.newsspool1.arcor-online.net X-Trace: DXC=P71EcJTTE6lUoRk[hk2Walic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgbkkVBCm`oO1jnc\616M64>jLh>_cHTX3jm1\`KR1]mT^h X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:11474 Date: 2010-06-08T13:35:19+02:00 List-Id: On 08.06.10 12:10, Niklas Holsti wrote: > Martin Krischik wrote: > >> just about as painful as using local packages to add static variables >> to Ada procedures. > > Later Martin Krischik wrote: > >> function f returns Integer >> >> package i is >> g : Integer := 0; >> end i; >> >> begin >> i.g := i.g + 1; >> return i.g; >> end f; > > If you mean the latter code to be an example of the former task (add > static variable), I believe you are mistaken. I thought, too, that a new variable decl inside the local package would still be elaborated each time. The initilization of g confirms when tested. But then I thought, surprise!, doubted everything I thought I had learned about Ada. Looking at this: with Ada.Text_IO; use Ada.Text_IO; procedure Sttc is type T is range 0 .. 10; procedure A is package P is -- local package V: T; -- presumably static? end P; begin if P.V'Valid then P.V := P.V + 1; else P.V := T'First; end if; Put_Line (T'Image(P.V)); end A; begin A; A; A; end Sttc; $ ./sttc 0 1 2 3 $ Compiled with or without -gnatVa. But this seems to be accidental, V is just a variable that isn't initialized, living on the stack. Confirmation: with Ada.Text_IO; use Ada.Text_IO; procedure Sttc is type T is range 0 .. 10; procedure A is package P is V: T; end P; begin if P.V'Valid then P.V := P.V + 1; else P.V := T'First; end if; Put_Line (T'Image(P.V)); end A; procedure Ovrwrt_Stk is X : T; begin X := T'First; end Ovrwrt_Stk; begin A; Ovrwrt_Stk; A; Ovrwrt_Stk; A; Ovrwrt_Stk; A; end Sttc; $ ./sttc 0 1 1 1 $ Phew. Back to normal.