comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: Elaborate_All on child package
Date: Sun, 4 Sep 2011 22:21:58 -0700 (PDT)
Date: 2011-09-04T22:21:58-07:00	[thread overview]
Message-ID: <c97951be-ca0a-4cac-9212-caf56d16dfad@l2g2000vbn.googlegroups.com> (raw)
In-Reply-To: 19a85f93-3cd2-4054-8022-21ba294d53e3@glegroupsg2000goo.googlegroups.com

On 3 Sep., 18:57, "Rego, P." <pvr...@gmail.com> wrote:
> However, should it be done this way? Due to it is already "withed" to the parent package, so why have I make a new with? I mean: why is the following code incorrect:
>    pragma Elaborate_All (Forum_Test);
>    package Forum_Test.Childp is <....>
>
> and why is the following code correct?
>    with Forum_Test;
>    pragma Elaborate_All (Forum_Test);
>    package Forum_Test.Childp is <....>

The simple (and unsatisfying) answer: Because the RM says so.

So your problem is based on lack of understanding of elaboration. A
program begins execution by elaborating all compilation units. There
is no order prescribed for this except that what is mentioned in a
context clause must be elaborated before.

So applied to your example, elaboration order can be:

1. Forum_Test'Spec
2. Forum_Test'Body
3. Forum_Test.Childp'Spec
With this sequence, your program would have worked. However your
compiler, GNAT, chose another sequence:

1. Forum_Test'Spec
2. Forum_Test.Childp'Spec
3. Forum_Test'Body
When Childp calls Construct, you get an elaboration check that fails.

There are several ways to force certain elaboration orders. One is to
use pragma Elaborate_Body in every spec whenever the spec defines a
function - this forces the body to be elaborated directly after the
spec. Sometimes, this is not possible.

Other pragmas are Preelaborate, Elaborate_All, Elaborate, Pure. See RM
10.2.1 Elaboration Control.



  reply	other threads:[~2011-09-05  5:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-03 16:57 Elaborate_All on child package Rego, P.
2011-09-05  5:21 ` AdaMagica [this message]
2011-09-05  9:28   ` Georg Bauhaus
2011-09-10 19:24   ` Rego, P.
2011-09-06  7:05 ` Egil Høvik
2011-09-06 12:51   ` Robert A Duff
2011-09-06 13:46     ` Niklas Holsti
2011-09-06 14:23       ` Robert A Duff
2011-09-07  5:03         ` AdaMagica
2011-09-07 10:49           ` Georg Bauhaus
replies disabled

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