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,1e12d8e0da8e9a65 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-05 08:04:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!news.maxwell.syr.edu!newsfeed.cwix.com!newscon02.news.prodigy.com!newsmst01.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr12.news.prodigy.com.POSTED!not-for-mail From: "Pat Rogers" Newsgroups: comp.lang.ada References: <3C5FB880.6FD36A12@hotmail.com> Subject: Re: [HELP] Why is 'Adjust' not called here ??? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: NNTP-Posting-Host: 208.191.180.40 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr12.news.prodigy.com 1012925035 ST000 208.191.180.40 (Tue, 05 Feb 2002 11:03:55 EST) NNTP-Posting-Date: Tue, 05 Feb 2002 11:03:55 EST Organization: Prodigy Internet http://www.prodigy.com X-UserInfo1: TSUGWWCEJKVOBTT^]BCB^]\@PJ_^PBQLGPQRJWQHBATBTSUBYFWEAE[YJLYPIWKHTFCMZKVMB^[Z^DOBRVVMOSPFHNSYXVDIE@X\BUC@GTSX@DL^GKFFHQCCE\G[JJBMYDYIJCZM@AY]GNGPJD]YNNW\GSX^GSCKHA[]@CCB\[@LATPD\L@J\\PF]VR[QPJN Date: Tue, 05 Feb 2002 16:03:55 GMT Xref: archiver1.google.com comp.lang.ada:19637 Date: 2002-02-05T16:03:55+00:00 List-Id: "Didier Pieroux" wrote in message news:3C5FB880.6FD36A12@hotmail.com... > Hello, > > To make it short: why is 'Adjust' not called during initialization by a > aggregate ? > > I give an example below illustrating my question. 'A.Instance' is a > controlled type with Initialize, Adjust and Finalize redefined to print > their name. > > I thought that the elaboration of > > Item1 : A.Instance := (Ada.Finalization.Controlled with 10); > > would call the 'A.Adjust' procedure... It is not the case. However, > 'A.Adjust' is called as expected after the elaboration of > > Item2 : A.Instance := Item1; It is because the first case is initialization via an aggregate, but the second case (immediately above) is not via an aggregate. > I check that behavior with both the Gnat and Aonix compiler. So, I am > clearly missing something here, and I can't find the answer in my books > (Barnes, Cohen, Ben-Ari and the RM) > > Also, could someone > - Explain me the rational for not calling 'Adjust' in the first case ? See below. > - Give me the key reference(s) in the RM from which this behavior can be > deduced ? RM 7.6 {17.1/1} {For an aggregate of a controlled type whose value is assigned, other than by an assignment_statement or a return_statement, the implementation shall not create a separate anonymous object for the aggregate. The aggregate value shall be constructed directly in the target of the assignment operation and Adjust is not called on the target object.} 17.h.1/1 Reason: This is necessary to prevent elaboration problems with deferred constants of controlled types. Consider: package P is type Dyn_String is private; Null_String : constant Dyn_String; ... private type Dyn_String is new Ada.Finalization.Controlled with ... procedure Finalize(X : in out Dyn_String); procedure Adjust(X : in out Dyn_String); Null_String : constant Dyn_String := (Ada.Finalization.Controlled with ...); ... end P; 17.h.3/1 When Null_String is elaborated, the bodies of Finalize and Adjust clearly have not been elaborated. Without this rule, this declaration would necessarily raise Program_Error (unless the permissions given below are used by the compiler). --- Patrick Rogers Consulting and Training in: http://www.classwide.com Real-Time/OO Languages progers@classwide.com Hard Deadline Schedulability Analysis (281)648-3165 Software Fault Tolerance