在Ada中使用IN OUT [英] The use of IN OUT in Ada

查看:103
本文介绍了在Ada中使用IN OUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是ada中的一些代码

Given below is some code in ada

  with TYPE_VECT_B; use TYPE_VECT_B;

  Package TEST01 is
  procedure TEST01
           ( In_State   : IN     VECT_B ;
             Out_State  : IN OUT VECT_B );

  function TEST02
           ( In_State   : IN     VECT_B ) return Boolean ;

  end TEST01;

TYPE_VECT_B包的规范和主体也定义如下

The TYPE_VECT_B package specification and body is also defined below

  Package TYPE_VECT_B is

  type VECT_B is array (INTEGER  range <>) OF BOOLEAN  ;

  rounded_data : float ;
  count : integer ;
  trace : integer ;
  end TYPE_VECT_B;

  Package BODY TYPE_VECT_B is
  begin
   null;
 end TYPE_VECT_B;

变量In_State和Out_State到底是什么意思?我认为In_State表示输入变量。我只是对Out_State的实际含义感到困惑?

What does the variable In_State and Out_State actually mean? I think In_State means input variable. I just get confused to what actually Out_State means?

推荐答案

子程序可以读取但不能写入参数。 in 是默认设置。在Ada 2012之前,仅允许函数具有 in 参数。实际参数是一个表达式。

An in parameter can be read but not written by the subprogram. in is the default. Prior to Ada 2012, functions were only allowed to have in parameters. The actual parameter is an expression.

一个 out 参数表示先前的值没有意义。子程序应写入参数。写入参数后,子程序可以读回已写入的内容。退出时,实际参数将接收写入的值(该区域存在复杂性!)。实际参数必须是变量。

An out parameter implies that the previous value is of no interest. The subprogram is expected to write to the parameter. After writing to the parameter, the subprogram can read back what it has written. On exit the actual parameter receives the value written to it (there are complications in this area!). The actual parameter must be a variable.

in out 参数就像 out 参数,只是先前的值是有意义的,并且可以在分配前由子程序读取。例如,

An in out parameter is like an out parameter except that the previous value is of interest and can be read by the subprogram before assignment. For example,

procedure Add (V : Integer; To : in out Integer; Limited_To : Integer)
is
begin
   --  Check that the result wont be too large. This involves reading
   --  the initial value of the 'in out' parameter To, which would be
   --  wrong if To was a mere 'out' parameter (it would be
   --  uninitialized).
   if To + V > Limited_To then
      To := Limited_To;
   else
      To := To + V;
   end if;
end Add;

这篇关于在Ada中使用IN OUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆