From: Simon Wright <simon@pogner.demon.co.uk>
Subject: Re: local variables
Date: 1998/04/10
Date: 1998-04-10T00:00:00+00:00 [thread overview]
Message-ID: <x7v3efl8ty6.fsf@pogner.demon.co.uk> (raw)
In-Reply-To: 352E491F.4C6D@young.epc.lmms.lmco.com
"B.Voh" <voh@young.epc.lmms.lmco.com> writes:
> 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.
Current Ada is exactly like Ada83 in this respect; you get the effect
you want by using *package* variables.
-------- foo.h ---------
int f(void);
-------- foo.c ---------
static int fi = 0;
int f(void)
{
fi++;
return fi;
}
-------- foo.ads ---------
package foo is
function f return integer;
end foo;
-------- foo.adb ---------
package body foo is
fi : integer := 0;
function f return integer is
begin
fi := fi + 1;
return fi;
end f;
end foo;
-------------------------
OK, within foo.c the scope of fi is a bit wider than it would have
been if it'd been declared inside f(), but I don't see this as being
that big a deal.
Remember that if you use tasking (or, in C, threads) you will have to
protect accesses to fi; putting it inside f() won't help.
next prev parent 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 ` Robert Dewar
1998-04-10 0:00 ` Simon Wright [this message]
1998-04-10 0:00 ` Niklas Holsti
1998-04-10 0:00 ` Tucker Taft
1998-04-10 0:00 ` Robert Dewar
1998-04-13 0:00 ` Fergus Henderson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox