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,50856407da0f240e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.220.230 with SMTP id pz6mr22870019pbc.3.1340204270781; Wed, 20 Jun 2012 07:57:50 -0700 (PDT) Path: l9ni72706pbj.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: why this construct causes aliasing problem in 2012 with functions allowing In Out? Date: Wed, 20 Jun 2012 07:56:12 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2adb0da6-9b6e-4514-b703-f0a6261ecc5b@googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1340204270 2459 127.0.0.1 (20 Jun 2012 14:57:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 20 Jun 2012 14:57:50 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Date: 2012-06-20T07:56:12-07:00 List-Id: On Wednesday, June 20, 2012 1:24:11 AM UTC-7, Nasser M. Abbasi wrote: > looking at http://www.slideshare.net/AdaCore/ada-2012 > > (typing it myself looking at the screen) > > -------------------------- > function change(x,y : in out integer) return integer is > begin > x := x*2; > y := y*4; > return x+y; > end > > one , two : integer :=1; > begin > two := change(one,two)+ change(one,two); --> > end > ----------------------------- > > They say it will generate > > warning: result may differ if evaluated after actual in expression. > > I understand that the order of calls in the A()+B() is not defined. > i.e. A() can be called first, then B(), or B() first then A(). > > But the result should still be the same either way. So what > is the problem? Obviously, it *would* be a problem if you said two := change(one,two) - change(one,two); The language is designed to try to minimize order dependencies that could produce different results. Asking it to make special cases for commutative operators when both operands are identical expressions, is asking too much. It looks to me like whoever wrote that slide should have used "-" (or some other function) instead of "+", to avoid any possible confusion in people who realize that the order doesn't matter in this case. -- Adam