Skip to content

Instantly share code, notes, and snippets.

@kimtg
Last active May 25, 2016 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimtg/26353170510ebc25a343685c37abe150 to your computer and use it in GitHub Desktop.
Save kimtg/26353170510ebc25a343685c37abe150 to your computer and use it in GitHub Desktop.
with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.text_IO;
procedure Eval_Order is
function Minus(A, B : Integer) return Integer is (A - B);
function Get return Integer is
R : Integer;
begin
Ada.Integer_Text_IO.Get(R);
return R;
end;
begin
-- Arguments are evaluated from right to left.
Put_Line(Integer'Image(Minus(Get, Get)));
end Eval_Order;
@kimtg
Copy link
Author

kimtg commented May 18, 2016

$ gnatmake eval_order.adb
gcc -c eval_order.adb
gnatbind -x eval_order.ali
gnatlink eval_order.ali

$ ./eval_order
2 3
 1

@jrcarter
Copy link

ARM 6.4(8/2):

"For the execution of a subprogram call, the name or prefix of the call is evaluated, and each parameter_association is evaluated (see 6.4.1). ... These evaluations are done in an arbitrary order."

(http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-6-4.html)

Your version of GNAT used right-to-left in this case. It might use a different order for a different case. Even if it always uses right-to-left, another compiler, and even another version of GNAT, might use a different order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment