comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <nholsti@icon.fi>
Subject: Re: local variables
Date: 1998/04/10
Date: 1998-04-10T00:00:00+00:00	[thread overview]
Message-ID: <352E6B84.CD61C7C2@icon.fi> (raw)
In-Reply-To: 352E491F.4C6D@young.epc.lmms.lmco.com


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




  reply	other threads:[~1998-04-10  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-10  0:00 local variables B.Voh
1998-04-10  0:00 ` Niklas Holsti [this message]
1998-04-10  0:00 ` Tucker Taft
1998-04-10  0:00   ` Robert Dewar
1998-04-13  0:00     ` Fergus Henderson
1998-04-10  0:00 ` Robert Dewar
1998-04-10  0:00 ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox