Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer dereference in VHDL

Tags:

vhdl

I have not been able to understand how to dereference a pointer in VHDL.

What I have in mind is a C code like :

  int a;
  int* ptr_a;

  a = 42;
  ptr_a=&a;
  *ptr_a=451;// how can I do this ?

I tried to mimick this code in 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;

So how can I correctly modify a value through a pointer ?

like image 540
JCLL Avatar asked Jan 15 '23 01:01

JCLL


1 Answers

You can't directly. Access types are not "just like pointers" - they are to at least some extent distinct types of data storage.

This line does not create a pointer to a:

ptr_a     := new integer'(a);

It creates a data object with the same value as a and sets up ptr_a to reference it.

If you were to create another access type variable :

variable ptr_b : ptr_integer;

and set it to to point to ptr_a:

ptr_b := ptr_a;

then changes to ptr_b.all will reflect in ptr_a.all.

like image 68
Martin Thompson Avatar answered Jan 22 '23 07:01

Martin Thompson