comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Question about library unit elaboration order.
Date: Fri, 10 Aug 2007 12:32:09 -0700
Date: 2007-08-10T12:32:09-07:00	[thread overview]
Message-ID: <1186774329.543334.42150@m37g2000prh.googlegroups.com> (raw)
In-Reply-To: <46b902fd$0$25585$4d3efbfe@news.sover.net>

On Aug 7, 4:40 pm, "Peter C. Chapin" <pcha...@sover.net> 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






      parent reply	other threads:[~2007-08-10 19:32 UTC|newest]

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

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