* Does variable creation need Elaborate_Body?
@ 2017-11-15 2:10 Victor Porton
2017-11-15 2:17 ` Victor Porton
2017-11-15 9:56 ` AdaMagica
0 siblings, 2 replies; 3+ messages in thread
From: Victor Porton @ 2017-11-15 2:10 UTC (permalink / raw)
package X is
-- pragma Elaborate_Body;
function F return Integer;
procedure Init;
end X;
package body X is
V: Integer;
function F return Integer is
begin
return V;
end;
procedure Init is
begin
V := 123;
end;
end X;
-------------------
Does the above program need Elaborate_Body pragma for elaboration of "V:
Integer;"?
Intuitively, "V: Integer;" does nothing. But it is a declaration which needs
to be elaborated.
Does it elaborate correctly without Elaborate_Body?
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Does variable creation need Elaborate_Body?
2017-11-15 2:10 Does variable creation need Elaborate_Body? Victor Porton
@ 2017-11-15 2:17 ` Victor Porton
2017-11-15 9:56 ` AdaMagica
1 sibling, 0 replies; 3+ messages in thread
From: Victor Porton @ 2017-11-15 2:17 UTC (permalink / raw)
And what if we replace "V: Integer;" with "V: Integer := 11;"?
Victor Porton wrote:
> package X is
>
> -- pragma Elaborate_Body;
>
> function F return Integer;
>
> procedure Init;
>
> end X;
>
> package body X is
>
> V: Integer;
>
> function F return Integer is
> begin
> return V;
> end;
>
> procedure Init is
> begin
> V := 123;
> end;
>
> end X;
>
> -------------------
>
> Does the above program need Elaborate_Body pragma for elaboration of "V:
> Integer;"?
>
> Intuitively, "V: Integer;" does nothing. But it is a declaration which
> needs to be elaborated.
>
> Does it elaborate correctly without Elaborate_Body?
>
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Does variable creation need Elaborate_Body?
2017-11-15 2:10 Does variable creation need Elaborate_Body? Victor Porton
2017-11-15 2:17 ` Victor Porton
@ 2017-11-15 9:56 ` AdaMagica
1 sibling, 0 replies; 3+ messages in thread
From: AdaMagica @ 2017-11-15 9:56 UTC (permalink / raw)
Am Mittwoch, 15. November 2017 03:10:57 UTC+1 schrieb Victor Porton:
> package X is
>
> -- pragma Elaborate_Body;
>
> function F return Integer;
>
> procedure Init;
>
> end X;
> ...
> Does it elaborate correctly without Elaborate_Body?
The problem here is not the variable V in the body. The problem is the function F returning some value (might be anything). If the body of X has been elaborated before the call of F, there is no elaboration problem; in your case, V may be uninitialized if Init has not yet be called.
If F is called before the body of X has been elaborated, you get Program_Error (elaboration check), because the body of F is not yet known. Elaborate_Body guarantees that the body of X is elaborated together with the spec.
This body of X has the same elaboration problem:
package body X is
function F return Integer is
begin
return 1;
end;
end X;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-15 9:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-15 2:10 Does variable creation need Elaborate_Body? Victor Porton
2017-11-15 2:17 ` Victor Porton
2017-11-15 9:56 ` AdaMagica
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox