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: a07f3367d7,57f8540942f8e060 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!m24g2000prn.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Initialization and Finalization of limited object "returned" by a function Date: Thu, 11 Feb 2010 17:05:59 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <75a9f860-ad3c-49a0-b2a1-a8f1386e6ff6@x10g2000prk.googlegroups.com> <2801be3a-afd6-4d14-ad7f-feb23a511f02@a5g2000yqi.googlegroups.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 1265936760 25906 127.0.0.1 (12 Feb 2010 01:06:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 12 Feb 2010 01:06:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m24g2000prn.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9140 Date: 2010-02-11T17:05:59-08:00 List-Id: On Feb 11, 2:49=A0pm, Hibou57 (Yannick Duch=EAne) wrote: > On 11 f=E9v, 22:51, Adam Beneschan wrote:> For an exten= ded return, > > > =A0 =A0return R : T; > > > R is not a local variable, and it isn't "assigned" into the anonymous > > object; thus, there's no Adjust, and R is not finalized when the > > function returns > > Yes > > > (but the anonymous object will be finalized later, > > Which anonymous object ? Any time you call a function, the language semantics say that there is a "result object" to hold the function result. The function is called and puts its result in the result object. The reason the language calls it a distinct object is so that it can define when Adjusts and finalizations take place for this object. I may have erred by calling it an anonymous object. In Ada 95, I believe it was referred to as an anonymous object. In Ada 2005, if you use the extended return syntax, this gives a name to the result object (as Bob said), so maybe it's wrong to call it "anonymous", although there are parts of the RM that refer to "the anonymous object representing the result of a function call" or words to that effect. In any case, at the place where the function is called, you can't refer to this result object by any name. My earlier post may have been confusing because I was referring to two separate parts of the function call process: (1) how the value gets INTO the result object and (2) what the caller does with the result object AFTER the function is finished. For #1, when the function says return EXPR; then EXPR is assigned into the result object (which means that an Adjust has to be done), *unless* the result object gets built in place, which is always the case if EXPR is a function call and the type is limited. But if the function says return NAME : TYPE [do ... end return]; then NAME is a name that *refers* to the result object; NAME does *not* declare another object that will get assigned to the result object as in the earlier example. For #2, if you say X : T :=3D Func(...); The call to Func means that there is a "result object". When Func is called, the value gets put into the result object somehow, as mentioned above. Then, if X is not built in place, the result object is copied to X, which means that an Adjust is done, and then the result object is finalized. However, if X *is* built in place (as it must be if T is limited), then the call to Func puts a value into the result object; and then after that point, X starts "magically" referring to that result object. There's no copying, and no Finalize. That's what the RM means by "mutating into". Yes, the language is a bit weird, and I know it was difficult for the ARG to find the right words to express what was supposed to happen. Anyway, the end result of all this is that, for a limited type (or in any other case where X is built in place), there isn't supposed to be any finalization until X disappears. In your case, if you're seeing your A_Type get finalized while Tested_Interface still exists, this is incorrect behavior. Hope this clears things up. If instead I've just created more confusion, I apologize and promise to refrain from making things worse by trying to explain myself any more. -- Adam