comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: Elaboration circularity with generics
Date: Sun, 15 Jan 2012 08:55:57 -0800 (PST)
Date: 2012-01-15T08:55:57-08:00	[thread overview]
Message-ID: <3a04e681-8180-4722-9b19-414173073d8e@m4g2000vbc.googlegroups.com> (raw)
In-Reply-To: m2sjjhq4vs.fsf@pushface.org

On 14 Jan., 23:46, Simon Wright <si...@pushface.org> wrote:
> AdaMagica <christ-usch.gr...@t-online.de> writes:
> > A unit can only be instantiated if it is fully elaborated.
> > I guess GNAT chose the elaboration order P'Spec, P.Q'Spec, P'Body
> > (crash since P.Q'body is not elaborated).
> > This dependence is not present for nongeneric units.
>
> > Perhaps addition of pragma Elaborate_Body to P.Q helps.
>
>    with P.Q;
>    pragma Elaborate (P.Q);          <<<<<<< does the trick for me
>    package body P is

Of course this works, but in my opinion, Elaborate_Body is better
because it has to be applied just once to P.Q, whereas Elaborate has
to be applied on every unit withing P.Q.

As a general rule of thumb I think Elaborate_Body should be applied
whenever a unit provides functions that are used in the spec of other
units providing initial values or constants, such like:

package P is
  pragma Elaborate_Body;  -- prevents elaboration error when F is
called
  function F (...) return T;
end P;

with P;  -- no need for "pragma Elaborate (P);"
package Q is
  V: [constant] T := P.F (...);
end Q;



  reply	other threads:[~2012-01-15 16:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-14 15:09 Elaboration circularity with generics Maciej Sobczak
2012-01-14 16:13 ` Martin Dowie
2012-01-14 16:17 ` AdaMagica
2012-01-14 22:46   ` Simon Wright
2012-01-15 16:55     ` AdaMagica [this message]
2012-01-16 15:09       ` Simon Wright
2012-01-16 17:15         ` AdaMagica
2012-01-14 16:26 ` AdaMagica
2012-01-14 22:01 ` Georg Bauhaus
2012-01-15 17:15   ` Maciej Sobczak
2012-01-15 17:43     ` AdaMagica
2012-01-16 17:02       ` Adam Beneschan
2012-01-16 14:34     ` Robert A Duff
2012-01-16 21:29       ` Maciej Sobczak
2012-01-16 21:52         ` Adam Beneschan
2012-01-16 22:25         ` Robert A Duff
replies disabled

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