Roger Federer
Roger Federer

Reputation: 17

how to return assosciative arrays in system verilog

hello want to know how are associative arrays passed as return values

code:

function abc()
begin
int value[string][string];
value = def();
end

function int def()
begin
int new_value[string][string];
//logic to populate the array
return new_value;
end

I am seeing the following error: The type of target is int. While, the type of source is int$[string][string].

How to handle this and pass the assosciative array seamlessly?

Upvotes: 1

Views: 2224

Answers (1)

dave_59
dave_59

Reputation: 42673

For a function to return an aggregate type, you need to declare a typedef first, then use that as the return value.

typedef int AA_t[string][string];
function AA_t def();
  AA_t new_value; 
  //logic to populate the array
  return new_value;
endfunction

Once you have the typedef you might as well use it everywhere.

Upvotes: 6

Related Questions