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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,878cc452376823e0 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!u12g2000prd.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Generic body Date: Thu, 15 May 2008 07:59:34 -0700 (PDT) Organization: http://groups.google.com Message-ID: <511b5387-c94f-4293-91f0-d8a4c4447894@u12g2000prd.googlegroups.com> References: <482C0178.5020501@gmail.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1210863574 15666 127.0.0.1 (15 May 2008 14:59:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 15 May 2008 14:59:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u12g2000prd.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:75 Date: 2008-05-15T07:59:34-07:00 List-Id: On May 15, 2:25 am, S=E9bastien wrote: > I read a lot of stuff about elaboration, I'm not a master of the subject > yet, but I understand a bit about it. I thought that Elaborate_All was > about dynamic check vs static check? (flat -gnatE for circular dependancy)= 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 :=3D 0; function Next_Counter return Integer is begin Counter :=3D 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