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: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: local variables Date: 1998/04/10 Message-ID: #1/1 X-Deja-AN: 342844592 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <352E491F.4C6D@young.epc.lmms.lmco.com> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1998-04-10T00:00:00+00:00 List-Id: B.Voh (voh@young.epc.lmms.lmco.com) wrote: : Does new ADA support a retention of local variables similar to Fortran's : "save" or C's "static" declaration? No. However, the "new" Ada (aka Ada 95) does allow variable declarations to be interleaved with subprogram bodies in a package body, so it is easier to localize package-level variables with a subprogram that needs one. In my experience, however, it is quite common that there are several subprograms in a given abstraction that all need access to the "static" variables retaining state across calls. So moving such variables to the package level usually makes good sense anyway. : 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. I would be curious in what way this is crippling. All declarations in a package body are "encapsulated," including package-level variables used to retain state between calls of a given subprogram. For what it is worth, Java also omits the notion of "local static" variables. Here is an example which takes advantage of the Ada 95 relaxed ordering for variable declarations and subprogram bodies, to allow package-level variables to be grouped with associated subprograms: package Abstraction is procedure Op1(...); procedure Bump_Counter(Next : out Integer); end Abstraction package body Abstraction is procedure Op1(...) is begin -- do something interesting end Op1; Counter : Integer := 0; -- "static" variable used by Bump_Counter procedure Bump_Counter(Next : out Integer) is begin Counter := Counter + 1; Next := Counter; end Bump_Counter; end Abstraction; In any case, "Counter" is not visible outside the Abstraction package, and so it is still "encapsulated." -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA