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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2f8b28565f329871 X-Google-Attributes: gid103376,public From: Niklas Holsti Subject: Re: local variables Date: 1998/04/10 Message-ID: <352E6B84.CD61C7C2@icon.fi>#1/1 X-Deja-AN: 342850528 Content-Transfer-Encoding: 7bit References: <352E491F.4C6D@young.epc.lmms.lmco.com> Content-Type: text/plain; charset=us-ascii Organization: Telecom Finland News Service Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-04-10T00:00:00+00:00 List-Id: B.Voh wrote: > > Does new ADA support a retention of local variables similar to Fortran's > "save" or C's "static" declaration? > In my last encounter with ADA, some years back, I found that to be a > rather crippling ommission and often working against the very principles > (encapsulation) it was supposed to champion. The local variables of an Ada 95 subprogram are still created for each call of the subprogram, and deleted when the call returns. However, just as in Ada 83, the way to save local (private, encapsulated) variables from call to call is to put the subprogram in a package, and declare the variables in the body of the package but outside the subprogram: package Example is procedure Count_Something; end Example; package body Example is Saved_Count: integer := 0; procedure Count_Something is begin Saved_Count := Saved_Count + 1; end Count_Something; end Example; Here, the Saved_Count variable lives and retains its last-assigned value as long as the package Example lives; if Example is a library-level package, this means the whole duration of the program run. Is this what you were looking for? If not, what is the "crippling" problem? - Niklas