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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,df7d6571cb90914a X-Google-Attributes: gid103376,public From: Tom Moran Subject: Re: C's static variable Date: 1997/09/07 Message-ID: <34136A90.7FEE@bix.com>#1/1 X-Deja-AN: 270635887 References: <34109F10.52E2@communique.net> Organization: InterNex Information Services 1-800-595-3333 Reply-To: tmoran@bix.com Newsgroups: comp.lang.ada Date: 1997-09-07T00:00:00+00:00 List-Id: > Does anyone know how in Ada to produce the equivalent of a static > variable in C? 1) Any variable declared in a package in Ada is analogous to a 'global'ly declared variable in C. But in Ada it can be inside the private part of the specification, or in the body of the package, in which case it retains its value like a C global, but is invisible to other packages, unlike C. 2) If you want something like declaring a static *inside* a C function, but it makes no sense to have a separate package usable by anybody, then you can make an internal package: package body Whatever is ... package Special_Routine_With_A_Static is function F(... ; private Static_Variable : integer_or_something := some_initial_value; end Special_Routine_With_A_Static; package body Special_Routine_With_A_Static is function F(... -- uses and modifies Static_Fariable (in a task-safe/unsafe way) end F; end Special_Routine_With_A_Static; ... -- more of package Whatever, including calls -- on Special_Routine_With_A_Static.F -- and perhaps a 'renames' of that to a better name end Whatever;