按结果调用示例

时间:2016-05-13 12:39:54

标签: parameter-passing ada algol

是否有任何适当的例子来解释逐个调用? (不是伪代码)

我了解到ALGOL 68,Ada可以这样使用,
但是我找不到任何明确的Call-by-Result示例。

1 个答案:

答案 0 :(得分:0)

我自己做的。

<强>伪代码

begin
integer n;
procedure p(k: integer);
    begin
    n := n+1;
    k := k+4;
    print(n);
    end;
n := 0;
p(n);
print(n);
end;

使用Ada语言实施

<强> call.adb

with Gnat.Io; use Gnat.Io;

procedure call is
x : Integer;
Procedure  NonSense (A: in out integer) is  
begin
    x := x + 1;
    A := A + 4;
    Put(x);
end NonSense;

begin 
    x := 0;
    NonSense (x);
    Put(" ");
    Put(x);
    New_Line;
end call;

由于Ada使用按结果调用的方式,结果应为1 4.(可以通过将此代码输入online-Ada-compiler&#34; http://www.tutorialspoint.com/compile_ada_online.php&#34;)进行检查。 p>

并且,其他结果应用不同的传递参数类型应该是...
按价值呼叫:1 1
请参考:5 5
比较&gt;按值结果调用:1 4)

相关问题