comp.lang.ada
 help / color / mirror / Atom feed
* C to Ada (static)
@ 1996-04-26  0:00 Heinz-Gerd Kuester
  1996-04-26  0:00 ` Theodore E. Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Heinz-Gerd Kuester @ 1996-04-26  0:00 UTC (permalink / raw)




How do I translate this to ADA?

void myfunc (void)
{
	static int number; /* <= the static stuff in Ada? */

}

Thank you
Heinz-Gerd Kuester

-- 
Heinz-Gerd Kuester




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

* Re: C to Ada (static)
  1996-04-26  0:00 C to Ada (static) Heinz-Gerd Kuester
  1996-04-26  0:00 ` Theodore E. Dennison
@ 1996-04-26  0:00 ` Joerg Rodemann
  1996-04-26  0:00 ` Laurent Guerby
  2 siblings, 0 replies; 5+ messages in thread
From: Joerg Rodemann @ 1996-04-26  0:00 UTC (permalink / raw)



Heinz-Gerd Kuester (100270.2522@CompuServe.COM) wrote:

> How do I translate this to ADA?

> void myfunc (void)
> {
> 	static int number; /* <= the static stuff in Ada? */

> }

Hello!

Hm, as far as I've digged into Ada-95 I would suppose there is no _direct_
equivalent for this code fragment. Although used very often this construct
has some nasty foot traps --- I experienced lots of students struggling
with its edges (I have to count myself among them...).

The point is the following: suppose two parts of a program each of them is
doing something and is only remotely concerned about the other. They
both want to use your myfunc...maybe they manipulate your static i one
after the other assuming their _own_ old value is still in there. (If i is
a unique number for the whole process everything will be okay on the other
side).

No, please do not tell me, you always think about this before and avoid
this problem. My solutions often lot very different from what I started with
and from what I expected to get...

Now let's turn to your problem again: I believe a good solution is to 
confine your function to a package:

   package Somewhat is
   
      procedure MyProcedure;

   private

      i : Integer := 0;   -- Perhaps this can be specified more seriously
                          -- by your needs, e.g. subtype Natural range 0..256?

   end Somewhat;

This way you can be assured that i holds its previous value till the next
MyProcedure call. On the other hand you are able to use it in to different
control currents with no interference by making the above mentioned package
generic and using different instantiations.

Hope this helps

Greetings

George Rodemann




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

* Re: C to Ada (static)
  1996-04-26  0:00 C to Ada (static) Heinz-Gerd Kuester
  1996-04-26  0:00 ` Theodore E. Dennison
  1996-04-26  0:00 ` Joerg Rodemann
@ 1996-04-26  0:00 ` Laurent Guerby
  2 siblings, 0 replies; 5+ messages in thread
From: Laurent Guerby @ 1996-04-26  0:00 UTC (permalink / raw)



Heinz-Gerd Kuester writes
: How do I translate this to ADA?
: 
: void myfunc (void)
: {
: 	static int number; /* <= the static stuff in Ada? */
: 
: }

   Something like (in a body definition) :

Number : Integer;

procedure My_Procedure is
begin
   null; 
end My_Procedure;

: Thank you
: Heinz-Gerd Kuester

-- 
--  Laurent Guerby, student at Telecom Bretagne (France), Team Ada.
--  "Use the Source, Luke. The Source will be with you, always (GPL)."
--  http://www-eleves.enst-bretagne.fr/~guerby/ (GATO Project).
--  Try GNAT, the GNU Ada 95 compiler (ftp://cs.nyu.edu/pub/gnat).




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

* Re: C to Ada (static)
  1996-04-26  0:00 C to Ada (static) Heinz-Gerd Kuester
@ 1996-04-26  0:00 ` Theodore E. Dennison
  1996-04-27  0:00   ` Robert Dewar
  1996-04-26  0:00 ` Joerg Rodemann
  1996-04-26  0:00 ` Laurent Guerby
  2 siblings, 1 reply; 5+ messages in thread
From: Theodore E. Dennison @ 1996-04-26  0:00 UTC (permalink / raw)



Heinz-Gerd Kuester wrote:
> 
> How do I translate this to ADA?
> 
> void myfunc (void)
> {
>         static int number; /* <= the static stuff in Ada? */
> 
> }

Ada doesn't have anything like static variables. To get the same
functionality, you will have to declare the variable globally 
somewhere visible to that routine. 

Example:

package body My_Package is

   Number : Integer;

   procedure My_Procedure is
   begin
      ...series of statements...
   end My_Procedure;

end My_Package;


-- 
T.E.D.          
                |  Work - mailto:dennison@escmail.orl.mmc.com  |
                |  Home - mailto:dennison@iag.net              |
                |  URL  - http://www.iag.net/~dennison         |




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

* Re: C to Ada (static)
  1996-04-26  0:00 ` Theodore E. Dennison
@ 1996-04-27  0:00   ` Robert Dewar
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1996-04-27  0:00 UTC (permalink / raw)



T.E.D said

"Ada doesn't have anything like static variables. To get the same
functionality, you will have to declare the variable globally
somewhere visible to that routine.

Example:

package body My_Package is

   Number : Integer;

   procedure My_Procedure is
   begin
      ...series of statements...
   end My_Procedure;

end My_Package;"

That could confuse. Number is not a global variable in the normal sense,
it is local to the package body and can be seen only from the package
body.





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

end of thread, other threads:[~1996-04-27  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-26  0:00 C to Ada (static) Heinz-Gerd Kuester
1996-04-26  0:00 ` Theodore E. Dennison
1996-04-27  0:00   ` Robert Dewar
1996-04-26  0:00 ` Joerg Rodemann
1996-04-26  0:00 ` Laurent Guerby

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