How to copy contents of array to queue

This shows compilation error

module top;

  //example of queue
  bit [31:0] src[5] = '{1,2,3,4,5};

int j = 2;
int q1[] = {1,2,3,4}; int q2[] = {7,8};
int q3;
q3 = src;
initial begin

    foreach(q3[i])
      $display(q3[i]);
  end
    
   
  
endmodule

In reply to Dora:

fixed/dynamic array can not directly assigned to queue.


module top;

//example of queue
bit [31:0] src[5] = '{1,2,3,4,5};
int j = 2;
int q1[$] = {1,2,3,4};
int q2[$] = {7,8};
int q3[$];

initial begin

  foreach(src[i]) begin
    q3.push_back(src[i]);
    $display(q3[i]);
  end 
end



endmodule

In reply to Dora:

Dora,

There are 2 problems with the code you posted.

  1. The
    q3 = src;
    statement is outside the procedural initial block
  2. You did not declare q3 as a queue. It needs to be declared as a queue with matching element types of unpacked array to make the assignment statement work.
module top;

//example of queue
bit [31:0] src[5] = '{1,2,3,4,5};
int j = 2;
int q1[$] = {1,2,3,4};
int q2[$] = {7,8};
bit [31:0]  q3[$];
q3 = src;
initial begin
    q3 = src;
    foreach(q3[i])
      $display(q3[i]);
    end
endmodule