Hello,
The code is working as expected but am wondering how are we able to access without creating class instances for the queue of widgets as we are operating on NULL handles in it’s current form.
I expected this to error out when compiled but it works. Please clarify. If we are pushing anything to the queue which is actually a class, it can’t be valid as there is no memory allocated.
class widget;
int id;
bit to_remove;
endclass : widget
module top;
widget q[$];
widget temp[$];
initial begin
widget w;
int num = $urandom_range(20,40);
for (int i = 0; i < num; i++) begin
w = new;
w.id = i;
w.to_remove = $urandom_range(0,1);
q.push_back(w);
$display("widget id:%02d, to_remove:%b", q[$].id, q[$].to_remove);
end
for (int i=0;i<num;i++) begin
w=q[i];
if(w.to_remove==0)
temp.push_back(w);
end
// write SV code to remove entries in q[$] that have to_remove==1
$display("\n\n-------------------------------------");
foreach(temp[i])
begin
$display("widget id:%02d, to_remove:%b --> OK", temp[i].id,temp[i].to_remove);
end
end
endmodule