在Ada中,当你分配Object.All时它意味着什么?

时间:2018-01-10 16:57:56

标签: ada

考虑以下任务:

procedure Assign(Original : myAccessType) is    
Other : myAccessType;

begin    
   Other.all := Original.all;
   Other.IntegerValue := Original.IntegerValue;  
end

我不确定第一个任务是做什么的。 .All在作业中有什么意义?并且,仍然需要整数值的第二个赋值吗?

2 个答案:

答案 0 :(得分:7)

第一项作业将引发Constraint_Error,因为在Ada中,访问值已初始化为null

假设你写了

Other : myAccessType := new myType;

然后

Other.all := Original.all;

意味着(除非在那里使用Ada.FinalizationARM 7.6Original指向的位将被复制到Other指向的位中

因此没有必要进行第二次任务。

我不是专业的C程序员,但我认为你的代码等同于

typedef struct myType {
  int IntegerValue;
} *myAccessType;

void assign(myAccessType original)
{
  myAccessType other;     // uninitialized
  *other = *original;
  other->IntegerValue = original->IntegerValue;
}

答案 1 :(得分:1)

.all显式取消引用访问类型。