Function return array

function bit [7:0]payload_calc payl(int length,int data_size,int data[]);
    payl = new[length];
    reg [31:0][7:0] temp_data;//varible(packed array) used to to convert 256 bit data in to 8 bit form
    int a =0;
    reg [7:0] temp_payload[];
    temp_payload = new[length];
    for(int i=0;i<data_size;i++)begin
        temp_data = data[i];//data is 256 bit array
        for(int j=0;(j<32 && a<length);j++)begin
           temp_payload[a] = temp_data[j];
           `uvm_info("TEMP_PAYLOAD",$sformatf("temp_payload[%0d]    :   %0h",a,temp_payload[a]),UVM_HIGH)
           `uvm_info("TEMP_DATA",$sformatf("tmp[%0d]       :   %0h",j,temp_data[j]),UVM_HIGH)
           a++;
        end
    end
      payload_calc= temp_payload;
    endfunction : payload_calc

i want a function which return the array … but i trying the above one which shows compilation error…how to overcome this error

thanks

In reply to lalithjithan:

Follow the example given in stackoverflow

In reply to lalithjithan:

The syntax for function declarations does permit anything other than simple types and type names. So you must use a typedef name fore the return type.

typedef bit [7:0] byte_da_t[];
function byte_da_t payl(int length,int data_size,int data[]);

In reply to dave_59:

mr dave,

can you give an SV example to usege of function as an array?

regards,
Anil T

In reply to anil tirumalasetty:

Try this code please:

module top;
  import uvm_pkg::*;
  `include "uvm_macros.svh"

  
  typedef bit [7:0] byte_da_t[];
         
  function byte_da_t payl(int length,int data_size,int data[]);
    byte_da_t temp_payload;
    
    logic [31:0][7:0] temp_data;//varible(packed array) used to to convert 256 bit data in to 8 bit form
    int a;
    payl = new[length];
    a =0;
   
    temp_payload = new[length];
    for(int i=0;i<data_size;i++)begin
        temp_data = data[i];//data is 256 bit array
        for(int j=0;(j<32 && a<length);j++)begin
           temp_payload[a] = temp_data[j];
           `uvm_info("TEMP_PAYLOAD",$sformatf("temp_payload[%0d]    :   %0h",a,temp_payload[a]),UVM_HIGH)
           `uvm_info("TEMP_DATA",$sformatf("tmp[%0d]       :   %0h",j,temp_data[j]),UVM_HIGH)
           a++;
        end
    end
      return temp_payload;
  endfunction : payload_calc
  
  initial begin
    
  end  
  
endmodule

In reply to chr_sue:

Mr chr_sue

When we use the typedef bit [7:0] byte_da_t[];,
should we use the same type while calling the function ?

Br,
Athira

In reply to Athiras:

Of course, because your function is of this type.