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,a4cc6fdc99d3fe2a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-29 12:25:18 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: package body functionality Date: 29 May 2001 15:11:30 -0400 Organization: NASA Goddard Space Flight Center Message-ID: References: <9eoeiv$h8$1@eol.dd.chalmers.se> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 991164452 27174 128.183.220.71 (29 May 2001 19:27:32 GMT) X-Complaints-To: dscoggin@cne-odin.gsfc.nasa.gov NNTP-Posting-Date: 29 May 2001 19:27:32 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.6 Xref: archiver1.google.com comp.lang.ada:7849 Date: 2001-05-29T19:27:32+00:00 List-Id: f97stdi@dd.chalmers.se (Staffan Dittmer) writes: > the question might be a bit obscure but > considering the two package bodies below > > package body A is > variable: some_type:=call_some_function_outside_A; > end A; > > package body B is > variable: some_type; > begin > variable:=call_some_function_outside_B; > end B; > > I know that in B the variable will be assigned > every time a program using the package is run, This is seriously wrong! B.variable is _not_ set many times. It would be interesting to understand how you got that impression. B.variable will be set _once_, at "elaboration" time. Elaboration happens just before the main Ada program is run. All packages in the program are elaborated, in an order determined by the compiler. Note that if a function is called before its package is elaborated, the exception Program_Error is raised; this is before your main program gets to start. To be safe, package A should have a 'pragma Elaborate' for the package containing 'some_function_outside_A', and similarly for B. > > but is this also true for A, or will the variable in this case only > be assigned at compile time ? As for B, A.variable is set at elaboration time. -- -- Stephe