comp.lang.ada
 help / color / mirror / Atom feed
From: Tom Moran <tmoran@bix.com>
Subject: Re: C's static variable
Date: 1997/09/07
Date: 1997-09-07T00:00:00+00:00	[thread overview]
Message-ID: <34136A90.7FEE@bix.com> (raw)
In-Reply-To: 34109F10.52E2@communique.net



> Does anyone know how in Ada to produce the equivalent of a static
> variable in C?
1) Any variable declared in a package in Ada is analogous to a
'global'ly declared variable in C.  But in Ada it can be inside the
private part of the specification, or in the body of the package, in
which case it retains its value like a C global, but is invisible to
other packages, unlike C.
2) If you want something like declaring a static *inside* a C function,
but it makes no sense to have a separate package usable by anybody, then
you can make an internal package:
package body Whatever is
...
   package Special_Routine_With_A_Static is
     function F(...  ;
   private
     Static_Variable : integer_or_something := some_initial_value;
   end Special_Routine_With_A_Static;
   package body Special_Routine_With_A_Static is
     function F(...
        -- uses and modifies Static_Fariable (in a task-safe/unsafe way)
     end F;
   end Special_Routine_With_A_Static;
...  -- more of package Whatever, including calls 
     -- on Special_Routine_With_A_Static.F
     -- and perhaps a 'renames' of that to a better name
end Whatever;





      parent reply	other threads:[~1997-09-07  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-05  0:00 C's static variable RL
1997-09-05  0:00 ` Matthew Heaney
1997-09-07  0:00 ` Tom Moran [this message]
replies disabled

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