gpt4 book ai didi

ada - 在 Ada 中,分配 Object.All 是什么意思?

转载 作者:行者123 更新时间:2023-12-05 08:41:42 25 4
gpt4 key购买 nike

考虑以下分配:

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

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

我不太确定第一个作业在做什么。 .All 在作业中的意义是什么?还有,整数值的第二次赋值还需要吗?

最佳答案

第一个赋值将引发 Constraint_Error,因为在 Ada 中访问值被初始化为 null

假设你改为写

Other : myAccessType := new myType;

然后

Other.all := Original.all;

意味着(除非在那里使用了 Ada.FinalizationARM 7.6 )Original 指向的位将被复制到指向的位中通过其他

因此不需要做第二个作业。

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

typedef struct myType {
int IntegerValue;
} *myAccessType;

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

关于ada - 在 Ada 中,分配 Object.All 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48192460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com