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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,80e74153f40106ab X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-04 21:02:37 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Weird controlled behavior - Gnat 3.15p NT Date: Thu, 4 Sep 2003 23:04:34 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <5d6fdb61.0309040725.3403aa29@posting.google.com> <3F57B071.5030206@attbi.com> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:42162 Date: 2003-09-04T23:04:34-05:00 List-Id: "Robert I. Eachus" wrote in message news:3F57B071.5030206@attbi.com... > Jano wrote: > > > Now, I would assume that no Finalization could happen without a > > corresponding Initialization, so is this normal? Is something wrong in > > that read way? > > No object can be finalized that has not been initialized (or created as > part of an assignment with adjust)... No, that's not right either. Finalizable objects can be "initialized" three ways: -- Default initialization followed by a call to Initialize. -- Explicit initialization followed by a call to Adjust. -- Aggregate initialization. Note that the latter doesn't call anything. Also note that an abstraction can make the last illegal by declaring the type as a private type. In this case, it looks like GNAT is assigning temporaries, so there is a bit copy, followed by an Adjust call, and then a Finalize call for the temporary. That accounts for the "extra" calls. For a non-limited controlled type, you have to account for all three routines; they can get used implicitly even if you never wrote any assignments. Finally, Robert's basic point is correct: Finalize should always be designed to be called "extra" times on an object. I usually use something like: procedure Finalize (Obj : in out Object_Type) is begin if Obj.Inited then -- Finalize code. Obj.Inited := False; -- else not Initialized or already Finalized. end if; end Finalize; with Initialize setting the Initted flag. (Often, I use some data in the record for this purpose, rather than a dedicated flag; such as an allocated block of memory [if the pointer is null, the object is already Finalized].) Randy.