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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,2153d570c2f03e29 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.224.105.205 with SMTP id u13mr4328789qao.6.1355564830198; Sat, 15 Dec 2012 01:47:10 -0800 (PST) Received: by 10.49.39.99 with SMTP id o3mr1452525qek.14.1355564830115; Sat, 15 Dec 2012 01:47:10 -0800 (PST) Path: k2ni7qap.0!nntp.google.com!fc2no886281qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 15 Dec 2012 01:47:10 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=91.7.59.222; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf NNTP-Posting-Host: 91.7.59.222 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <7ad8ab3a-2a17-44d0-a64f-4cfb1288dc1c@googlegroups.com> Subject: Re: Question about library-level functions From: AdaMagica Injection-Date: Sat, 15 Dec 2012 09:47:10 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2012-12-15T01:47:10-08:00 List-Id: > What's the difference between a library-level(top-level?) function(A) and > a function(B) in a library-level package? Hm, I think the lifetime of the returned object is in both cases the same. > with Ada.Text_IO; > with lifetime; > with alloc; > procedure main is > begin > Ada.Text_IO.Put_Line ("before"); > declare > type A is access all lifetime.T; > P : A := A(alloc); Finalize may not be called in Alloc, since the object must be created in place (it's limited - there cannot be an intermediate object as in the unlimited case). > begin > -- P.all may be already finalized!!! I guess that, since P is unused, the compiler optimizes the sequence of calls and finalizes P first. > Ada.Text_IO.Put_Line ("lifetime"); Finalize must at the latest be called here before the block is left. > end; > Ada.Text_IO.Put_Line ("after"); > end main; > > % gnatmake -gnat2012 main.adb && ./main > > before > Initialize (0000000100100090) > Finalize (0000000100100090) <- !!!! > lifetime > after