Arrays SystemVerilog数组是按值传递还是按引用传递?
默认情况下,SystemVerilog是否按值或引用传递数组 例如:Arrays SystemVerilog数组是按值传递还是按引用传递?,arrays,system-verilog,Arrays,System Verilog,默认情况下,SystemVerilog是否按值或引用传递数组 例如: int array[5] = '{0,1,2,3,4}; some_function(array); // <-- value or reference? int数组[5]='{0,1,2,3,4}; 一些_函数(数组);// 默认情况下,SystemVerilog按值传递数组,复制整个数组 出于性能原因,建议尽可能通过引用传递数组 如果希望函数修改数组,请使用ref 如果希望函数读取数组,请使用const ref
int array[5] = '{0,1,2,3,4};
some_function(array); // <-- value or reference?
int数组[5]='{0,1,2,3,4};
一些_函数(数组);// 默认情况下,SystemVerilog按值传递数组,复制整个数组
出于性能原因,建议尽可能通过引用传递数组
- 如果希望函数修改数组,请使用
ref
- 如果希望函数读取数组,请使用
const ref
例如:
function void pass_by_value(int array[5], int queue[$], int assoc[int]);
// Default.
// A copy of the arrays is made in this function
endfunction
function void pass_by_ref(ref int array[5], ref int queue[$],
ref int assoc[int]);
// Original arrays are being referenced
endfunction
function void pass_by_const_ref(const ref int array[5],
const ref int queue[$],
const ref int assoc[int]);
// Original arrays are being referenced
// And they can be read but cannot be modified in this function
endfunction
EDA操场示例: