comp.lang.ada
 help / color / mirror / Atom feed
* STATIC Variables
@ 1998-07-23  0:00 Marc Enzmann
  1998-07-23  0:00 ` Corey Ashford
  1998-07-23  0:00 ` Robert Dewar
  0 siblings, 2 replies; 3+ messages in thread
From: Marc Enzmann @ 1998-07-23  0:00 UTC (permalink / raw)


Does Ada have an equivalent to C's STATIC declaration ?
I've found this to be very helpful in some signal-processing
and simulation algorithms.
I've thumbed through a number of Ada textbooks but didn't find
anything.
Any hints ?

Thanks,

Marc
--




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: STATIC Variables
  1998-07-23  0:00 STATIC Variables Marc Enzmann
@ 1998-07-23  0:00 ` Corey Ashford
  1998-07-23  0:00 ` Robert Dewar
  1 sibling, 0 replies; 3+ messages in thread
From: Corey Ashford @ 1998-07-23  0:00 UTC (permalink / raw)



Marc Enzmann wrote in message <35B6EC76.ED3B1493@infaut.et.uni-magdeburg.de>...
>Does Ada have an equivalent to C's STATIC declaration ?
>I've found this to be very helpful in some signal-processing
>and simulation algorithms.
>I've thumbed through a number of Ada textbooks but didn't find
>anything.
>Any hints ?
>
>Thanks,
>
>Marc
>--

You might want to use www.dejanews.com to look through past responses
to this question.

The standard answer is usually to wrap a package around the function,
and place the static variable within the package.  This slightly
complicates calling the function, but you could use a library level
wrapper function to make the package invisible.

e.g.

package foo is
   function bar (x:integer) return integer;
end foo;

package body foo is

   var : integer;

   function bar (x:integer) return integer is
   begin
      var := var + 1;
      ...
      return factorial(var) * x;
   end bar;

end foo;


function wrapped_bar (x: integer) return integer is
begin
    return foo.bar(x);
end wrapped_bar;


- Corey






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: STATIC Variables
  1998-07-23  0:00 STATIC Variables Marc Enzmann
  1998-07-23  0:00 ` Corey Ashford
@ 1998-07-23  0:00 ` Robert Dewar
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1998-07-23  0:00 UTC (permalink / raw)


Marc asks about static variables in Ada.

Unlike C, Ada always requires that the lifetime of a variable match the
corresponding lifetime of its declaration.

Static variables a la C violate this rule of course.

Howver, it is absolutely standard practice to get exactly this same
effect by simply including the necessary variables at the package
body level (i.e. put them in the package body in which your procedure
bodyt is declared).





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-07-23  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-07-23  0:00 STATIC Variables Marc Enzmann
1998-07-23  0:00 ` Corey Ashford
1998-07-23  0:00 ` Robert Dewar

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