comp.lang.ada
 help / color / mirror / Atom feed
From: Sébastien <seb.morand@gmail.com>
Subject: Re: Generic body
Date: Thu, 15 May 2008 15:40:27 +0000
Date: 2008-05-15T15:40:27+00:00	[thread overview]
Message-ID: <482C596B.5080609@gmail.com> (raw)
In-Reply-To: 

> I don't think so.  It's about elaboration order, and making sure that
> variables have a chance to get initialized before they're used.  If
> you have a package body:
> 
>    package body Pak2 is
>       Counter : Integer := 0;
>       function Next_Counter return Integer is
>       begin
>          Counter := Counter + 1;
>          return Counter;
>       end Next_Counter;
>    end Pak2;
> 
> In Ada semantics, the elaboration of Pak2's body is what initializes
> Counter to 0.  But if the elaboration of some other package (say Pak3)
> used Next_Counter before Pak2's body had a chance to be elaborated,
> Counter would be uninitialized and Next_Counter would return garbage.
> So it's necessary to ensure that Pak2's body is elaborated before Pak3
> is elaborated, and that's what the Elaborate pragmas are for.
> (Without the Elaborate pragmas, Pak2's body might be elaborated first
> anyway, but you can't be sure.)
> 
> That's how it works in Ada.  I know that GNAT has a big long chapter
> in the manual describing how it determines the elaboration order, but
> I'm not really familiar with the details.  But I'd use the pragmas
> anyway; even if GNAT would get things right without them, you may want
> to port to a different compiler at a later time.
> 
> In any case, I like Gautier's solution and I wish I'd thought of it;
> that avoids the Elaboration issues completely.
> 
>                                -- Adam

Ok thanks for precision, it's clearer for me about elaboration issue now.



  reply	other threads:[~2008-05-15 15:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-14 18:26 Generic body Sébastien
2008-05-14 21:49 ` Randy Brukardt
2008-05-14 21:51 ` Samuel Tardieu
2008-05-14 22:03 ` Adam Beneschan
2008-05-15  9:25   ` Sébastien
2008-05-15 14:59     ` Adam Beneschan
2008-05-15 15:40       ` Sébastien [this message]
2008-05-15  8:43 ` gautier_niouzes
2008-05-15 13:11   ` Sébastien
replies disabled

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