title: How to return a dynamic struct array from a function in SystemVerilog
body: <p>I am having issues figuring out the syntax for returning a dynamic struct array from a function. I have the following small example:</p>
  
  <pre><code>`timescale 1ns/10ps
  
   typedef struct{
      string     Name;
      int        Age;
   } PersonType;
  
  function  PersonType A []  getPeopleInfo();
     automatic string Name [50];//Max of 50 people
     automatic int Age [50];
     PersonType A [];
     /*Turns out we only have 3 people-&gt;this may change at runtime*/
     Name[0]="Jon";Age[0]=25;
     Name[1]="Ana";Age[1]=32;
     Name[2]="Ali";Age[2]=19;
  
    A=new[3];/*This size may change at runtime*/
     for(int idx=0;idx&lt;3;idx++)
       begin
          A[idx].Name=Name[idx];
          A[idx].Age=Age[idx];
       end
     return A;
  endfunction // getPeopleInfo
  
  module Test();
     PersonType A [];
  initial begin
     A=getPeopleInfo();
     for(int idx=0;idx&lt;A.size();idx++)
       begin
          $display(A[idx].Name);
          $display(A[idx].Age);
       end
  
  end
  endmodule // Test
  </code></pre>
  
  <p>When I modify the function so that it passes the dynamic struct array as argument ie:</p>
  
  <pre><code>void getPeopleInfo(output PersonType A []);
  </code></pre>
  
  <p>Then it works fine. Is it possible to return a dynamic struct array from a function?, if so what is the correct syntax?.</p>