comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: "Common" data
Date: 13 Oct 1994 13:45:16 GMT
Date: 1994-10-13T13:45:16+00:00	[thread overview]
Message-ID: <37jdlc$tre@watnews1.watson.ibm.com> (raw)
In-Reply-To: 9410121737.AA28756@eurocontrol.de

In article <9410121737.AA28756@eurocontrol.de>, Bob Wells #402
<wel@EUROCONTROL.DE> 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



  parent reply	other threads:[~1994-10-13 13:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-10-12 17:37 "Common" data Bob Wells #402
1994-10-12 14:38 ` Robert I. Eachus
1994-10-13  3:21   ` Tucker Taft
1994-10-13 11:47     ` Robert I. Eachus
1994-10-13 13:45 ` Norman H. Cohen [this message]
  -- strict thread matches above, loose matches on Subject: below --
1994-10-13 13:22 Keith Arthurs
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox