如何在 systemverilog 中 return 关联数组

how to return assosciative arrays in system verilog

你好想知道关联数组是如何作为 return 值传递的

代码:

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

我看到以下错误: 目标的类型是 int。 而源的类型是 int$[string][string].

如何处理这个问题并无缝传递关联数组?

对于 return 聚合类型的函数,您需要先声明一个 typedef,然后将其用作 return 值。

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

一旦您拥有了 typedef,您不妨随处使用它。