Can the indivdual variables of a SystemVerilog struct be incremented with ++?

*爱你&永不变心* 提交于 2020-01-03 04:24:10

问题


I have defined a structure with three integers, then created a dynamic array of the structure. Later in the code, I want to increment some of the integer values in the structure:

typedef struct {
  integer tc;
  integer pass;
  integer fail;
} score_t; 

score_t    scorecard[]; 
integer    tc_count;

initial
....
scorecard = new[`MAX_TC]; 
....
scorecard[tc_count].fail  = 0;
....
scorecard[tc_count].fail++;

However, when I compile in Aldec Active-HDL I get the following error:

Error: VCP2615 ../../../m3_test_load_tb.sv : (283, 33): 
                    scorecard[tc_count].fail is not l-value.

Is this a limitation of the language? I can assign to a temporary variable to do the increment operation and then put the value back in the struct, but that seems clumsy.


回答1:


The code compiles with modelsim 10.1d. I have tested it on EDA Playground.

Seems the Aldec tool does not like the line:

scorecard[tc_count].fail++;

As a workaround you can replace the line with:

scorecard[tc_count].fail += 1;

Now it compiles with Aldec tool as well. http://www.edaplayground.com/x/VpV



来源:https://stackoverflow.com/questions/27629778/can-the-indivdual-variables-of-a-systemverilog-struct-be-incremented-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!