我无法理解如何在 VHDL 中取消引用指针。
我想到的是这样的 C 代码:
int a;
int* ptr_a;
a = 42;
ptr_a=&a;
*ptr_a=451;// how can I do this ?
Run Code Online (Sandbox Code Playgroud)
我尝试在 VHDL 中模仿这段代码:
ptr_test : process
type ptr_integer is access integer;
variable a : integer;
variable ptr_a : ptr_integer;
begin
a := 42;
ptr_a := new integer'(a);
report "ptr now points to a : ptr=" & str(ptr_a.all);
ptr_a.all := 451;
report "ptr modified : ptr=" & str(ptr_a.all);
report "a is NOT modified : a =" & str(a);
wait;
end process;
Run Code Online (Sandbox Code Playgroud)
那么如何通过指针正确修改值呢?
你不能直接。访问类型“不像指针”——它们至少在某种程度上是不同的数据存储类型。
该行不会创建指向以下内容的指针a:
ptr_a := new integer'(a);
Run Code Online (Sandbox Code Playgroud)
它创建一个具有相同值的数据对象a并设置ptr_a引用它。
如果您要创建另一个访问类型变量:
variable ptr_b : ptr_integer;
Run Code Online (Sandbox Code Playgroud)
并将其设置为指向ptr_a:
ptr_b := ptr_a;
Run Code Online (Sandbox Code Playgroud)
然后 的更改ptr_b.all将反映在 中ptr_a.all。