comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Order of elaboration
Date: 1996/04/03
Date: 1996-04-03T00:00:00+00:00	[thread overview]
Message-ID: <4jtufg$h13@watnews1.watson.ibm.com> (raw)
In-Reply-To: 4jtggm$ipm@mal9000.mal.com

In article <4jtggm$ipm@mal9000.mal.com>, dgymer@mal9000.mal.com
(Dave 'Gizmo' Gymer) writes: 

|> Having waded through most of John Barnes' Ada95 book and made a lot of
|> progress with some CGI stuff, I can't quite decide whether the
|> following must always be true; it makes sense but I can't find
|> explicit confirmation in either Barnes' book or in RM95: 
|>
|> A child package must always be elaborated after it's parent(s).

Be careful to distinguish between program units and compilation units!
A package is a program unit.  If it is a library package, this program
unit typically consists of two compilation units--the package declaration
and the package body.  Elaboration is something defined for compilation
units.  Thus it makes no sense to speak of when a package is elaborated.
Instead, you can speak of when a package declaration is elaborated and
when a package body is elaborated.

The declaration of a child package must indeed be elaborated after the
declaration of its parent's declaration.  However, the body of the
parent can be elaborated any time after the declaration of the parent
(before the elaboration of the child declaration, between the
elaboration of the child declaration and the child body, or after the
declaration of the child body): 

                             parent declaration
                             /              \
                         parent body    child declaration
                                              |
                                           child body

|> So if the parent sets up an empty list and has some functions for
|> adding things to that list, the child can call those functions (sorry,
|> procedures; I'm still recovering from C++) without worrying about
|> whether the list has been initialized yet (and without using the
|> Elaborate pragma). Correct?

Incorrect.  You can't call those subprograms until the parent body has
been elaborated.  For one thing, if the initialization to an empty list
takes place inside the package body rather than the package declaration,
that won't happen until the package body has been elaborated.  For
another, the bodies of subprograms provided by the package are not
elaborated until the package body containing them is elaborated, and you
can't call a subprogram until its body has been elaborated.

If you put an Elaborate_Body pragma inside the parent package
declaration, it will force the parent body to be elaborated immediately
after the parent declaration, solving your problem.  Alternatively, you
could put an Elaborate or Elaborate_All pragma in the context clause of
whichever compilation unit (the child declaration or the child body)
calls the parent package's subprograms.

--
Norman H. Cohen    ncohen@watson.ibm.com




      reply	other threads:[~1996-04-03  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-03  0:00 Order of elaboration Dave 'Gizmo' Gymer
1996-04-03  0:00 ` Norman H. Cohen [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