I have the following function:
function void foo_arr_bit (int seed, ref bit [*] mem, string mem_name);
for (int i=0; i< mem.size(); i++)
mem[i] = my_randomize_int(seed, mem[i], mem_name);
endfunction: foo_arr_bit
I call the function by:
foo_arr_bit(seed, data_bit, "data_bit");
Where data_bit can be: bit [1:0]/ bit [2:0]/ bit [3:0]/ bit [4:0]/ bit [5:0] etc...
When I try to compile I got the following error: near "[": syntax error, unexpected [ , expecting IDENTIFIER or TYPE_IDENTIFIER or NETTYPE_IDENTIFIER.
[*]
is not the correct syntax for a dynamic array, use[]
.Your array can only be dynamic in the unpacked dimension. So you cannot have
bit [] mem_array
, but must havebit mem_array[]
.Finally a function using pass by reference cannot have a static lifetime. That is, it must be declared as automatic.
Edit: But even with these changes you face a bigger issue. Passing by reference demands very strict typing. There is no casting allowed so I expect there to be issues with type conversion.
Furthermore, passing by reference is not really necessary in your case. Use
inout
instead.