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.7 required=5.0 tests=BAYES_00,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,71f9c948bec0bcad X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-10-13 10:18:04 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!EU.net!uunet!newsgate.watson.ibm.com!watnews.watson.ibm.com!ncohen From: ncohen@watson.ibm.com (Norman H. Cohen) Newsgroups: comp.lang.ada Subject: Re: "Common" data Date: 13 Oct 1994 13:45:16 GMT Organization: IBM T.J. Watson Research Center Distribution: world Message-ID: <37jdlc$tre@watnews1.watson.ibm.com> References: <9410121737.AA28756@eurocontrol.de> Reply-To: ncohen@watson.ibm.com NNTP-Posting-Host: rios8.watson.ibm.com Date: 1994-10-13T13:45:16+00:00 List-Id: In article <9410121737.AA28756@eurocontrol.de>, Bob Wells #402 writes: |> G'day, |> Where abouts in the LRM does it say that I will only have one copy |> of the variable T in the following code? This is naturally what you |> would expect, that A.New_T_Value and B.New_T_Value would be working |> on the same T, but is this defined in the LRM? ... |> |> This is a trivialization of some comms code delivered to us, and we |> wanted to see if the behaviour was defined by the LRM. |> |> --------------------------------------- |> package Common is |> |> procedure Update_T; |> |> end Common; |> |> package body Common is |> |> T : Integer; |> |> procedure Update_T is |> |> begin |> |> .. |> code which updates the variable T; |> .. |> |> end Update_T; |> |> end Common; |> |> --------------------------------------- |> |> package A is |> |> procedure New_T_Value; |> |> end A; |> |> with Common; |> package body A is |> |> procedure New_T_Value is |> |> begin |> |> Common.Update_T; |> |> end New_T_Value; |> |> end A; |> |> --------------------------------------- |> |> package B is |> |> procedure New_T_Value; |> |> end B; |> |> with Common; |> package body B is |> |> procedure New_T_Value is |> |> begin |> |> Common.Update_T; |> |> end New_T_Value; |> |> end B; |> |> --------------------------------------- |> |> with A; |> with B; |> procedure Main is |> |> begin |> |> A.New_T_Value; |> |> B.New_T_Value; |> |> end Main; This kind of question is hard to answer because it is so instinctively obvious that there should be only one T. The easiest answer is "Because the LRM doesn't say anything to the contrary." Nonetheless, let's see if we can find justification that will satisfy a language lawyer. By 3.2.1(7), an object is created when its declaration is elaborated. 3.9(3) states that the elaboration of a declarative part consists of the elaboration of its declarative items in order. (This implies that each declaration is elaborated once,and each declard variable created once, each time the declarative part is elaborated.) 7.3(2) states that when a package body is elaborated, its declarative part is elaborated (once, since nothing is said to the contrary). (Thus T is created once each time the body of Common is elaborated.) 10.5(1) says that bodies of library units needed by the main program are elaborated before execution of the main program and 10.5(2) specifies that compilation units are elaborated in a certain order, which implies that each unit is only elaborated once. Thus T is created once, before execution of the main program. A rigorous proof would entail enumerating every paragraph of the RM and establishing that no paragraph provides some OTHER circumstance in which a declared variable is created or a variable declaration, declarative part, or body of a library package is elaborated. A more practical approach is to challenge anybody who claims that there is more than one T to justify this position using the RM, and to tear his justification to shreds. -- Norman H. Cohen ncohen@watson.ibm.com