【发布时间】:2014-04-30 18:53:45
【问题描述】:
默认情况下,SystemVerilog 是按值还是按引用传递数组?
例如:
int array[5] = '{0,1,2,3,4};
some_function(array); // <-- value or reference?
【问题讨论】:
标签: arrays system-verilog
默认情况下,SystemVerilog 是按值还是按引用传递数组?
例如:
int array[5] = '{0,1,2,3,4};
some_function(array); // <-- value or reference?
【问题讨论】:
标签: arrays system-verilog
默认情况下,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 Playground 示例:http://www.edaplayground.com/x/2m9
【讨论】: