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,2f8b28565f329871 X-Google-Attributes: gid103376,public From: Simon Wright Subject: Re: local variables Date: 1998/04/10 Message-ID: #1/1 X-Deja-AN: 343073651 X-NNTP-Posting-Host: pogner.demon.co.uk:158.152.70.98 References: <352E491F.4C6D@young.epc.lmms.lmco.com> X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 892304159 nnrp-01:21772 NO-IDENT pogner.demon.co.uk:158.152.70.98 Organization: At Home Newsgroups: comp.lang.ada Date: 1998-04-10T00:00:00+00:00 List-Id: "B.Voh" writes: > Does new ADA support a retention of local variables similar to Fortran's > "save" or C's "static" declaration? > In my last encounter with ADA, some years back, I found that to be a > rather crippling ommission and often working against the very principles > (encapsulation) it was supposed to champion. Current Ada is exactly like Ada83 in this respect; you get the effect you want by using *package* variables. -------- foo.h --------- int f(void); -------- foo.c --------- static int fi = 0; int f(void) { fi++; return fi; } -------- foo.ads --------- package foo is function f return integer; end foo; -------- foo.adb --------- package body foo is fi : integer := 0; function f return integer is begin fi := fi + 1; return fi; end f; end foo; ------------------------- OK, within foo.c the scope of fi is a bit wider than it would have been if it'd been declared inside f(), but I don't see this as being that big a deal. Remember that if you use tasking (or, in C, threads) you will have to protect accesses to fi; putting it inside f() won't help.