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,e859f774bbb3dfb3 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!wns14feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: another way to shoot yourself in the foot? References: <54157920-377a-441b-9b0b-f0c4f9ddffec@f36g2000hsa.googlegroups.com> <54435596-5e7f-4686-a2b7-1e22d7c4b186@p25g2000hsf.googlegroups.com> <483ugmvkl2ea.1hrqsq7ru4t1x$.dlg@40tude.net> <12dhu8e1w5ac9.1s9hzkf9d2rsy$.dlg@40tude.net> <21d80cc3-a3fb-49f5-a46e-6056bbef2ba7@y21g2000hsf.googlegroups.com> <1lbujyle8itjn$.vffs9far1ob9.dlg@40tude.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1214342690 12.201.97.213 (Tue, 24 Jun 2008 21:24:50 GMT) NNTP-Posting-Date: Tue, 24 Jun 2008 21:24:50 GMT Organization: AT&T ASP.att.net Date: Tue, 24 Jun 2008 21:24:50 GMT Xref: g2news1.google.com comp.lang.ada:852 Date: 2008-06-24T21:24:50+00:00 List-Id: Robert A Duff wrote: > > Not quite the "only" -- you could rename it. True. I forgot that one. > But in Ada 95, if you say: > > P(F(...)); > > where F returns limited, you are not passing a limited object, > but an implicit reference to some object that already existed before the > call to F. You can do that more clearly by having F return > an access type. I really think return-by-ref was a mistake. > Too bad we didn't think of it in 1992. For that matter, too > bad JDI didn't think of it in 1980. ;-) Of course you're passing a reference, since limited types are always passed by reference (since Ada 95). But I don't think that the object had to exist before the call to F: procedure Task_Return_Test is package Wrap is task type T; function F return T; end Wrap; package body Wrap is type T_Ptr is access T; function F return T is R : T_Ptr := new T; begin -- F return R.all; end F; task body T is -- null; begin -- T null; end T; end Wrap; procedure P (V : in Wrap.T) is -- null; begin -- P null; end P; begin -- Task_Return_Test P (V => Wrap.F); end Task_Return_Test; This is valid Ada 95, according to a compiler. > Well, there are only two ways a function call can be used: to initialize > a new object, or to update an existing object (i.e. on the right-hand > side of an assignment statement). But don't forget there are a dozen or > so different ways of creating new objects (components, parameters, > parent parts of aggregates, etc). All of these are allowed for > build-in-place function calls. The only thing that's not allowed is the > assignment statement. > > You can still say: > > P(F(...)); > > where F returns a limited type. Yes, there's a new object being created > (the formal parameter of P), and F is being used to initialize that > object (in place!). In Ada 2005, functions always return newly-created > objects, which I think is appropriate. I learned that functions return objects, and in this case the object is the actual parameter to P, not the formal parameter. The object is anonymous. Maybe that rule's changed for limited parameters in current Ada. But I take your point that F can be regarded as always building in place, wherever that place may be. > if F(...).Flag then ... > > The last one is pretty silly -- it creates a new limited object, > grabs a boolean flag out of it, and then throws the whole thing > away. It's also an example in which the object that F builds in is clearly anonymous, unlike the parameter of P above. -- Jeff Carter "So if I understand 'The Matrix Reloaded' correctly, the Matrix is basically a Microsoft operating system--it runs for a while and then crashes and reboots. By design, no less. Neo is just a memory leak that's too hard to fix, so they left him in ... The users don't complain because they're packed in slush and kept sedated." Marin D. Condic 65