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!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx09.iad.POSTED!not-for-mail From: Brad Moore User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Elaboration Question References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <_3spw.995330$Fo3.305798@fx09.iad> NNTP-Posting-Host: 68.145.219.148 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: 1420184954 68.145.219.148 (Fri, 02 Jan 2015 07:49:14 UTC) NNTP-Posting-Date: Fri, 02 Jan 2015 07:49:14 UTC Date: Fri, 02 Jan 2015 07:49:13 -0700 X-Received-Bytes: 2902 X-Received-Body-CRC: 2535384726 Xref: news.eternal-september.org comp.lang.ada:24312 Date: 2015-01-02T07:49:13-07:00 List-Id: On 2015-01-01 8:27 PM, Hubert wrote: > 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. > > 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? No, that's definitely worse, and really doesn't fix anything. There is nothing preventing someone from attempting to reference A, before Initialize is called. Initializing during elaboration is safer also because it happens only once, and via the environment task. Relying on programmers to initialize globals via explicit calls is error prone, and can even lead to concurrency problems if Initialize is called from more than one place. It's generally best to initialize global variables upon declaration, and usually you don't even need to think about elaboration. If there is a problem with elaboration, the compiler should tell you, and then you can think about how to resolve the elaboration issue, via the pragmas. Usually the error message from the compiler should give a good clue about the cause of the problem, and how to resolve it. Otherwise, typically the compiler does a good job of sorting out elaboration order all on its own. Brad > > > Thanks > > > > > > > --- > This email has been checked for viruses by Avast antivirus software. > http://www.avast.com >