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!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Question about library unit elaboration order. Date: Tue, 07 Aug 2007 20:00:37 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <46b902fd$0$25585$4d3efbfe@news.sover.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1186531239 18808 192.74.137.71 (8 Aug 2007 00:00:39 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 8 Aug 2007 00:00:39 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:fWlgtll6EWrChHd+oEb9UyZhCIo= Xref: g2news2.google.com comp.lang.ada:1371 Date: 2007-08-07T20:00:37-04:00 List-Id: "Peter C. Chapin" writes: > 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? No. It might work on some implementations, but raise Program_Error on others. However, if you are using GNAT, the default rules ensure that it will work. You have to use a switch to get the standard rules. > 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." Look up "dependence" in the index. Mostly, it's the with clauses. >... However, > it sounds like this is saying that my package body Example has an > elaboration dependency on package Other's body. No. The "with Other" creates a semantic dependence on the spec of other, not on the body. Note that the body of Other might say "with Example", so you don't want semantic dependences on bodies all the time. > 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. No. > However, if this is all true, then what is the point of pragma > Elaborate? The point is to create an elaboration dependence on the body of Other, to make sure that body is elaborated first. Note that you normally want Elaborate_All, not Elaborate, because Other's body might call something else, unknown to Example. >... 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? > I'm confused by this. There's a section in the GNAT User's Guide called "Elaboration Order Handling in GNAT", which explains all this stuff in great detail. Both the language rules, and the way GNAT deals with it. - Bob