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,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!198.186.194.247.MISMATCH!news-xxxfer.readnews.com!textspool1.readnews.com!bins2.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Tue, 07 Aug 2007 19:40:49 -0400 From: "Peter C. Chapin" User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Question about library unit elaboration order. Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <46b902fd$0$25585$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: c8ae4672.news.sover.net X-Trace: DXC=@Knb3iBW5lhg3`h;<25Q8aK6_LM2JZB_coESeXoc>OFj3?@`i3kGa5k?hMc 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." However, it sounds like this is saying that my package body Example has an elaboration dependency on package Other's body. Later in section 10.2 there is discussion about the way the environment task elaborates the library units. Paragraph 14 says, "The order of all included library_items is such that there are no forward elaboration dependences." So this seems to say (I think) that the language will ensure that my package Other gets elaborated before package Example. However, if this is all true, then what is the point of pragma Elaborate? I understand that I can use pragam Elaborate to force the relative order of elaboration of two library units. However, if those units already have a "semantic dependency," then pragma Elaborate should be unnecessary, right? Now, let's turn to John Barnes' "Programming in Ada 2005." In section 12.8 of that book on page 277, he shows an example that is very similar to mine. with P; package Q is I : Integer = Q.A; end Q; At the bottom of the page he says, "The key point is that the dependency rules only partially constrain the order in which the units are elaborated and so we need some way to impose order at the library level much as the linear text imposes elaboration order within a unit." He then shows the solution as with P; pragma Elaborate(P); package Q is I : Integer = P.A; end Q; I realize this example uses a package specification rather than a package body as in my example. Does that matter? It seems like package Q "depends semantically" on package P's body and so doesn't the reference manual assure us that the package P's body will get elaborated first even without the pragma Elaborate? I'm confused by this. Peter