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-Thread: 103376,353a5233f7ba7c0c X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!m37g2000prh.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Question about library unit elaboration order. Date: Fri, 10 Aug 2007 12:32:09 -0700 Organization: http://groups.google.com Message-ID: <1186774329.543334.42150@m37g2000prh.googlegroups.com> References: <46b902fd$0$25585$4d3efbfe@news.sover.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1186774330 10707 127.0.0.1 (10 Aug 2007 19:32:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 10 Aug 2007 19:32:10 +0000 (UTC) In-Reply-To: <46b902fd$0$25585$4d3efbfe@news.sover.net> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: m37g2000prh.googlegroups.com; posting-host=66.126.103.122; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1390 Date: 2007-08-10T12:32:09-07:00 List-Id: On Aug 7, 4:40 pm, "Peter C. Chapin" wrote: > Hi! Consider the following package body: > > with Other; > package body Example is > X : Integer; > begin > X := Other.Some_Function("Argument string"); > end Example; > > Clear if this is going to work right package Other's body needs to be > elaborated before package Example's body (both packages are library > units, by the way). My question is basically: does the Ada language > guarantee that this will happen without me doing any further work? > > Looking at the Ada 2005 reference manual, section 10.2, "Program > Execution", paragraph 9, I see: > > "The order of elaboration of library units is determined primarily by > the elaboration dependences. There is an elaboration dependence of a > given library_item upon another if the given library_item or any of its > subunits depends semantically on the other library_item." > > I'm not sure exactly what is meant by "depends semantically." It's explained in 10.1.1(26). If a library unit A has a "with B;" clause on it, then A depends semantically on B---but it only depends semantically on B's specification, not on B's body. I think that's the key thing you need to understand in order to understand the relevant language rules. (If you really want to dig deeper, 10.1.1(26) uses the term "mention", which is defined in 10.1.2(6), which depends on the term "denote", which is defined in 8.6(16), which says that an occurrence of a usage name denotes a declaration---and the "declaration" of a package is its specification, not its body.) > However, > it sounds like this is saying that my package body Example has an > elaboration dependency on package Other's body. No, unless you add an Elaborate or Elaborate_All pragma. As I mentioned above, Example's body does *not* semantically depend on Other's body (it depends semantically on Other's specification). So by 10.2(9), there is no elaboration dependency unless there's an Elaborate or Elaborate_All pragma. That should also explain what the purpose of those pragmas is. -- Adam