I am trying to create a queue of dynamic arrays. See the code below:
module tb;
typedef int packet_item[]; // dynamic array as a data type
packet_item packet_queue[$]; // queue of dynamic array elements
initial begin
packet_item ten = '{10,10};
packet_queue.push_back(ten);
packet_item eleven = '{11,11};
packet_queue.push_back(eleven);
foreach(packet_queue[i]) begin
$display("Index: %0d -- Elements: %0p",i, packet_queue[i]);
end
end
endmodule
This does not work at line packet_item eleven = '{11,11}; throwing a syntax error. However. if I move packet_queue.push_back(ten); after creating the array eleven, it works perfectly fine. See the modified code below:
module tb;
typedef int packet_item[]; // dynamic array as a data type
packet_item packet_queue[$]; // queue of dynamic array elements
initial begin
packet_item ten = '{10,10};
packet_item eleven = '{11,11};
packet_queue.push_back(ten);
packet_queue.push_back(eleven);
foreach(packet_queue[i]) begin
$display("Index: %0d -- Elements: %0p",i, packet_queue[i]);
end
end
endmodule
Can someone explain this behavior? Thank you