comp.lang.ada
 help / color / mirror / Atom feed
* why this construct causes aliasing problem in 2012 with functions allowing In Out?
@ 2012-06-20  8:24 Nasser M. Abbasi
  2012-06-20  8:26 ` Nasser M. Abbasi
  2012-06-20 14:56 ` Adam Beneschan
  0 siblings, 2 replies; 6+ messages in thread
From: Nasser M. Abbasi @ 2012-06-20  8:24 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-06-21 20:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-20  8:24 why this construct causes aliasing problem in 2012 with functions allowing In Out? Nasser M. Abbasi
2012-06-20  8:26 ` Nasser M. Abbasi
2012-06-20 14:56 ` Adam Beneschan
2012-06-20 15:14   ` Dmitry A. Kazakov
2012-06-21 20:06     ` Randy Brukardt
2012-06-21 20:00   ` Randy Brukardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox