Could sv function return a Multidimensional Arrays

return a array like
bit[7:0] marray[8][30];

in sv

In reply to designer007:

Yes, but you need to declare the return type using a typedef. The function declaration syntax does no allow any return types more complicated than a simple identifier with optional packed dimension…

In reply to dave_59:

typedef bit[7:0] marray[8][30];

function marray funcname(…);

is that correct?

In reply to dave_59:

typedef bsix mem_type [0:3]; // array of four ‘bsix’ elements
mem_type ba [0:7]; // array of eight ‘mem_type’ elements

so ba is array of 8*4 ‘bsix’ elements?

In reply to designer007:

SV function cannot return bare multidimensional array. You should typedef the array, then you can make use of it to return the array.
Please refer the below example for returning multidimensional array.


module top;
  typedef bit[7:0]data1;
  typedef data1 data2[4][6];
  
  function data2 func();
    bit[7:0]array[4][6];
    array[1][2]=5;    //randomly assigning some value
    $display("array is %p",array);
    return array;
  endfunction
  
  initial begin
    $display("data2 is %p",func());
  end
endmodule

Result:-

array is '{'{'h0, 'h0, 'h0, 'h0, 'h0, 'h0}, '{'h0, 'h0, 'h5, 'h0, 'h0, 'h0}, '{'h0, 'h0, 'h0, 'h0, 'h0, 'h0}, '{'h0, 'h0, 'h0, 'h0, 'h0, 'h0}} 
data2 is '{'{'h0, 'h0, 'h0, 'h0, 'h0, 'h0}, '{'h0, 'h0, 'h5, 'h0, 'h0, 'h0}, '{'h0, 'h0, 'h0, 'h0, 'h0, 'h0}, '{'h0, 'h0, 'h0, 'h0, 'h0, 'h0}}

In reply to designer007:

In reply to dave_59:
typedef bsix mem_type [0:3]; // array of four ‘bsix’ elements
mem_type ba [0:7]; // array of eight ‘mem_type’ elements
so ba is array of 8*4 ‘bsix’ elements?

Yes.

To summarize, a function can return any data type, but some complex data types require using a typedef.