comp.lang.ada
 help / color / mirror / Atom feed
From: rodemann@mathematik.uni-ulm.de (Joerg Rodemann)
Subject: Re: C to Ada (static)
Date: 1996/04/26
Date: 1996-04-26T00:00:00+00:00	[thread overview]
Message-ID: <4lr8it$9uj@rigel.rz.uni-ulm.de> (raw)
In-Reply-To: 4lr2eq$o3c$1@mhadf.production.compuserve.com


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




  reply	other threads:[~1996-04-26  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-26  0:00 C to Ada (static) Heinz-Gerd Kuester
1996-04-26  0:00 ` Joerg Rodemann [this message]
1996-04-26  0:00 ` Theodore E. Dennison
1996-04-27  0:00   ` Robert Dewar
1996-04-26  0:00 ` Laurent Guerby
replies disabled

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