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!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!transit3.readnews.com!news-xxxfer.readnews.com!news-out.readnews.com!transit4.readnews.com!panix!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: another way to shoot yourself in the foot? Date: Tue, 24 Jun 2008 19:02:26 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: 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> <87abhablrx.fsf@ludovic-brenta.org> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1214348546 24166 192.74.137.71 (24 Jun 2008 23:02:26 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 24 Jun 2008 23:02:26 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:02L3RoLy9uZbc5tQrkW/WCx0bEc= Xref: g2news1.google.com comp.lang.ada:857 Date: 2008-06-24T19:02:26-04:00 List-Id: Ludovic Brenta writes: > Robert A Duff writes: >> 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. > [...] >> In Ada 2005, functions always return newly-created objects, which I >> think is appropriate. > > This makes me wonder whether there is an actual difference in the way > the compiler handles such returns. Yes, very different in the case of limited types. In Ada 83, F returns its result by copy, and the address of this copy is passed to P. In Ada 95, F returns the address of some object outside F, and this address is passed to P. In Ada 2005, the formal of P is allocated at the call site, and the address of that is passed to F, which puts its result there. This address is then passed to P. Except if the size is not known at the call site, things get more complicated. And if controlled types or task types are involved, then extra implicit parameters are passed to F (who is the master of this thing, who is supposed to activate it, etc). >...For example, has GNAT changed a > lot in this area? Yes. We're talking about months of work by at least two people at AdaCore (one of whom was me). >...Do the Ada 95 and Ada 2005 compatibility modes use > antirely different compilation strategies? Yes. And if you try to mix them, it won't work. >> 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. > > Yes but "grabbing a boolean flag" might consist in passing the limited > object as a parameter to a primitive function named Flag, which might > then pass it down to any number of subprograms with all sorts of side > effects. One could write an arbitrarily large program like this :) Good point. I was talking about the case where the result is a limited record with a component called Flag, which is silly. You are talking about the case where Flag is a primitive operation, which is not silly. - Bob