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=2.0 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,50856407da0f240e,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.193.129 with SMTP id ho1mr22012836pbc.8.1340180656487; Wed, 20 Jun 2012 01:24:16 -0700 (PDT) Path: l9ni71718pbj.0!nntp.google.com!news2.google.com!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: why this construct causes aliasing problem in 2012 with functions allowing In Out? Date: Wed, 20 Jun 2012 03:24:11 -0500 Organization: Aioe.org NNTP Server Message-ID: Reply-To: nma@12000.org NNTP-Posting-Host: KdJUrTuvv3Zv/s8pPxNluw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-06-20T03:24:11-05:00 List-Id: 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? Assume the first change(one,two) is called. Then after that call, we will have ------------------------- two := 6 + change(2,4); (1) then the next change() is called using the updated actual (the two on the LHS can't be updated yet) two := 6 + 20; (2) hence now two becomes 26. ------------------------ Same result will happen if we do it the other way two := change(2,4) + 6; (1) then the next change is called two := 20 + 6; (2) hence two is 26. Is there another combination of mixing things up that I am missing? thanks, --Nasser