问题
Now I'm trying to digging the systemverilog as the below
denaliCdn_ahbTransaction burst1;
task sendTransfers;
burst1= new;
burst1.Direction = DENALI_CDN_AHB_DIRECTION_WRITE;
burst1.FirstAddress = 32'h4020;//16416 M3 and M0 to S1
burst1.Kind = DENALI_CDN_AHB_BURSTKIND_INCR4;
burst1.Size = DENALI_CDN_AHB_TRANSFERSIZE_HALFWORD;
burst1.Data = new [8];
foreach (burst1.Data[ii])
burst1.Data[ii] = ii;
void'(activeMaster1.transAdd(burst1,0));
....
endtask
Especially, from here , how does ii be decided it's value without initialized ?
foreach (burst1.Data[ii])
burst1.Data[ii] = ii;
how does a variable to be decided it's value without it's initialize in systemverilog?
回答1:
There is a general answer and a specific answer to your question.
The general answer is that all types in System-Verilog initialise to specific values:
int 0
real 0.0
string ""
logic 1'bx
However, the specific answer to your question is that the code you specifically identify
foreach (burst1.Data[ii])
burst1.Data[ii] = ii;
is actually performing initialisation rather than relying on it. The dynamic array burst1.data
is constructed with 8 elements in the line
burst1.Data = new [8];
The line
foreach (burst1.Data[ii])
iterates over that array, looping 8 times, once for each element. The variable ii
takes the value of the index of each element in the array, ie 0 to 7. The line
burst1.Data[ii] = ii;
Sets element ii
of the array to the value ii
and so is initialising the array.
来源:https://stackoverflow.com/questions/47569029/how-does-a-variable-to-be-decided-its-value-without-its-initialize-in-systemve