考虑以下任务:
procedure Assign(Original : myAccessType) is
Other : myAccessType;
begin
Other.all := Original.all;
Other.IntegerValue := Original.IntegerValue;
end
Run Code Online (Sandbox Code Playgroud)
我不确定第一项任务是做什么的..All在任务中有什么意义?并且,仍然需要整数值的第二次赋值吗?
第一个分配将提升Constraint_Error,因为在Ada中访问值被初始化为null.
假设你写了
Other : myAccessType := new myType;
Run Code Online (Sandbox Code Playgroud)
然后
Other.all := Original.all;
Run Code Online (Sandbox Code Playgroud)
意味着(除非在那里有一些使用Ada.Finalization,ARM 7.6)指向的位Original将被复制到指向的位Other.
因此,没有必要进行第二次任务.
我不是专业的C程序员,但我认为你的代码相当于
typedef struct myType {
int IntegerValue;
} *myAccessType;
void assign(myAccessType original)
{
myAccessType other; // uninitialized
*other = *original;
other->IntegerValue = original->IntegerValue;
}
Run Code Online (Sandbox Code Playgroud)