comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Elaboration Question
Date: Fri, 02 Jan 2015 07:56:04 +0000
Date: 2015-01-02T07:56:04+00:00	[thread overview]
Message-ID: <lywq55pqej.fsf@pushface.org> (raw)
In-Reply-To: Xeopw.842131$No4.595859@fx19.iad

Hubert <herrdoktor@fumanchu.com> writes:

> For a newcomer to Ada, elaboration is one of the toughest things to
> understand. My understanding is so, that if you have for instance a
> variable in the package body, say :
>
> A : Integer := 0;
>
> then this variable must be initialized at some point and that's what
> elaboration does.
> The problem then occurs with the order in which elaboration occurs in
> different package that depend on each other etc.
> There are pragmas for the programmer to take control of the
> elaboration sequence but I have the feeling that may complicate
> things. especially when you want to make a library that should be
> independent and that's supposed to be be released to others at some
> point.

The GNAT User Manual has a section on elaboration[1].

The ARM's elaboration model is what GNAT calls the dynamic model, and
does indeed (in general) require that you insert elaboration
pragmas. GNAT's default elaboration uses the static model, where the
compiler works out the elaboration order for itself.

Sometimes the static model is over-pessimistic; in my experience,
usually because of library level tasks (which start running, and may
make calls, during elaboration). This is rare, and most GNAT programmers
forget about elaboration issues.

See the "Default Behavior in GNAT - Ensuring Safety" section of [1] for
how to get GNAT to tell you what elaboration pragmas to insert;
especially useful if you're considering porting to a different compiler.

> So may question is, is it better to just leave those variables
> unitialized and then initialize them later for instance:
>
> A : Integer;
>
> PROCEDURE Initialize IS
> BEGIN
>    A:= 0;
> END Initialize;
>
> Would that be generally better?

I would say not. There might, after all, be a chain of Initialize calls
required; very complicated to manage.

[1] https://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Elaboration-Order-Handling-in-GNAT.html


  reply	other threads:[~2015-01-02  7:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-02  3:27 Elaboration Question Hubert
2015-01-02  7:56 ` Simon Wright [this message]
2015-01-02 22:16   ` Randy Brukardt
2015-01-02 14:49 ` Brad Moore
2015-01-02 11:08   ` Mark Lorenzen
2015-01-02 13:35     ` David Botton
2015-01-02 15:11     ` sbelmont700
2015-01-02 21:57       ` Niklas Holsti
2015-01-06  2:33         ` Randy Brukardt
2015-01-06  8:17           ` Niklas Holsti
2015-01-06 20:06             ` Randy Brukardt
2015-01-03  9:45 ` Jean François Martinez
2015-01-03  9:50   ` Hubert
2015-01-03 18:43     ` Jean François Martinez
2015-01-04  1:57       ` Hubert
2015-01-04 12:05       ` Simon Wright
replies disabled

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