comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <pchapin@sover.net>
Subject: Question about library unit elaboration order.
Date: Tue, 07 Aug 2007 19:40:49 -0400
Date: 2007-08-07T19:40:49-04:00	[thread overview]
Message-ID: <46b902fd$0$25585$4d3efbfe@news.sover.net> (raw)

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



             reply	other threads:[~2007-08-07 23:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-07 23:40 Peter C. Chapin [this message]
2007-08-08  0:00 ` Question about library unit elaboration order Robert A Duff
2007-08-08  0:32   ` Peter C. Chapin
2007-08-10 19:32 ` Adam Beneschan
replies disabled

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