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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,10ed08559aef1b44 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-01 07:28:35 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: STATIC types in ADA? Date: Fri, 1 Mar 2002 10:33:58 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <3c7f8fd6$0$7055$43695faf@reader> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:20647 Date: 2002-03-01T10:33:58-05:00 List-Id: wrote in message news:3c7f8fd6$0$7055$43695faf@reader... > Do STATIC data types (like C++ has) exist in ADA? > > By this I mean, is there a way I can define a variable so that > when I call a procedure and set a value (say 5.0) and then > exit the procedure and come back into it at a later time, the > variable would still have the same value (i.e., 5.0)? Just declare the object in a static scope (a package): package P is F : Float := 0.0 end; with P; procedure Op is begin P.F := 5.0; end; Realize that a variable declared in a package is equivalent to an object declared in a C++ namespace, or as a static member of a class: //n.hpp namespace N { extern float f; } //n.cpp float N::f; or //c.hpp class C { public: static float f; //... }; //c.cpp float C::f; Often variables are hidden in the body of the package, so you could write it as: package P is procedure Op; end; package body P is F : Float := 0.0; procedure Op is begin F := 5.0; end; end P; That would translate as: //n.hpp namespace N { void op(); } //n.cpp namespace { float f; } void N::op() { f = 5; } or //c.hpp class C { public: static void op(); //... private: static float f; //... }; //c.cpp float C::f; void C::op() { f = 5; } Actually, you could declare f in an anonymous namespace in the implementation file c.cpp, instead of as a static variable of the class. This lets you hide it completely. One of my complaints about C++ is that you often have to put things in the private part of the class declaration, up in the header file, instead of in the implementation file. Thus in order to get visibility, I pay with a compilation dependency. I haven't found a satisfactory way around this.