Unspecified size array as return type of a function

Hello everyone,

VHDL has this possibility to declare and use functions which have, as return type,unsized std_logic_vector, something that would look like this:


function myWeirdFunction(param1, param2, param3: std_ulogic_vector) return std_ulogic_vector is
variable var1, var2 : std_ulogic_vector(param2'high downto param2'low);
begin
--rest of the function
return param3;
end myWeirdFunction;

is there a way to do the same thing in Systemverilog ?
and can I use the pre-defined functions $high() and $low() to express the

param2'high downto param2'low

part?
I did something like this:


typedef logic empty[];
function empty myWeirdFunction(empty param1,empty param2,empty param3);
logic var1[$high(param2):$low(param2)], var2[$high(param2):$low(param2);
//rest of the function
end

Thanks in advance.

In reply to Yasmine4:
SystemVerilog does not have this feature when it comes to packed arrays (integral vectors). It’s not really needed because integral types are weak compared to the strong types in VHDL. This means integral vector lengths to not have to match or be explicitly cast to match in arguments passing or other operations. You can declare your function with variables of a maximum width, and where needed, pass in the actual width of the arguments passed in to it.

There are ways of parameterizing a function by making it a static method of a parameterized class. See section 13.8 Parameterized tasks and functions in the 1800-2017 LRM.

In reply to dave_59:

In reply to Yasmine4:
SystemVerilog does not have this feature when it comes to packed arrays (integral vectors). It’s not really needed because integral types are weak compared to the strong types in VHDL. This means integral vector lengths to not have to match or be explicitly cast to match in arguments passing or other operations. You can declare your function with variables of a maximum width, and where needed, pass in the actual width of the arguments passed in to it.
There are ways of parameterizing a function by making it a static method of a parameterized class. See section 13.8 Parameterized tasks and functions in the 1800-2017 LRM.

Thank you for your answer.