如何在systemverilog中处理struct initilization

时间:2022-02-25 19:54:16

I have the code as below but it failed at compile error.

我有如下代码,但它在编译错误时失败。

typedef struct {
    logic [7:0] mem_data[1024];
} mem_blk;

mem_blk m_mem[];
...
...
logic [7:0] data = 'h12;
m_mem[3].mem_data[0] = data;

the error information is : Error- [SV-RTOOBAW] Reference to out of bound array word

错误信息是:错误 - [SV-RTOOBAW]引用超出范围的数组字

1 个解决方案

#1


0  

Dynamic arrays need to be allocated using new[], or a copy from an array of the same time. So you need to do

需要使用new []分配动态数组,或者同时使用数组中的副本。所以你需要这样做

m_mem = new[4];

Before you can reference m_mem[3].

在你可以参考m_mem之前[3]。

Or maybe you meant to declare an associative array instead of a dynamic array.

或者你可能想要声明一个关联数组而不是动态数组。

mem_blk m_mem[bit [15:0]];

Then a write to m_mem[3] allocates that entry.

然后写入m_mem [3]分配该条目。

#1


0  

Dynamic arrays need to be allocated using new[], or a copy from an array of the same time. So you need to do

需要使用new []分配动态数组,或者同时使用数组中的副本。所以你需要这样做

m_mem = new[4];

Before you can reference m_mem[3].

在你可以参考m_mem之前[3]。

Or maybe you meant to declare an associative array instead of a dynamic array.

或者你可能想要声明一个关联数组而不是动态数组。

mem_blk m_mem[bit [15:0]];

Then a write to m_mem[3] allocates that entry.

然后写入m_mem [3]分配该条目。