From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Elaboration Question Date: Fri, 02 Jan 2015 07:56:04 +0000 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="da19c0dc8eec016b1dd8c302a793eb7c"; logging-data="18379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qc9Xlzk/a6eKNR5Lk3gh2AaXyNahoGCk=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:UevAsPcq44wiK9rYkFsCB1mpt9I= sha1:2FgNKYo84VxTx36dnuj5cmjuga8= Xref: news.eternal-september.org comp.lang.ada:24313 Date: 2015-01-02T07:56:04+00:00 List-Id: Hubert 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