From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9c4622dc4c4e0179 X-Google-Attributes: gid103376,public From: rodemann@mathematik.uni-ulm.de (Joerg Rodemann) Subject: Re: C to Ada (static) Date: 1996/04/26 Message-ID: <4lr8it$9uj@rigel.rz.uni-ulm.de>#1/1 X-Deja-AN: 151584226 references: <4lr2eq$o3c$1@mhadf.production.compuserve.com> organization: University of Ulm, SAI, Germany newsgroups: comp.lang.ada Date: 1996-04-26T00:00:00+00:00 List-Id: 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