program test();
logic [7:0] a[];
a = new[10];
endprogram
I try to new
a dynamic array in a program
, and I compiled it with VCS, but it failed.
The error shows that:
Following verilog source has syntax error : “test1.sv”, 20: token is
‘=’
a = new[10];
a = new[10];
This is a procedual statement, so it should be put within some kind of procedual block, e.g. initial
block:
program test();
logic [7:0] a[];
initial begin
a = new[10];
end
endprogram
This has nothing to do with program blocks, which I suggest you avoid anyways.
You can new
a dynamic array, but the constructor needs to be either in procedural code, or part of a variable declaration initialization.
module test;
logic [7:0] a[];
initial begin
a = new[10];
end
function automatic f;
logic p7:0] b = new[10];
b[2] = 3;
endfunction
endmodule