system verilog的array的问题, 欢迎来讨论.
时间:10-02
整理:3721RD
点击:
在标准的12.4.2中:
Elements of dynamic arrays, queues, and associative arrays that are passed by reference may get removed
from the array or the array may get resized before the called function or task completes. The specific array
element passed by reference shall continue to exist within the scope of the called tasks or functions until they
complete. Changes made to the values of array elements by the called task or function shall not be visible
outside the scope of those tasks or functions if those array elements were removed from the array before the
changes were made. These references shall be called outdated references.
那如果变成了outdated reference会怎么样?
还有, 我怎么样直接传参数给一个"queue of string"
例如, 定义一个functionAAA, 参数为string的queue类型sq[$]
virtual function void AAA (string sq [$])
...
endfunction
调用这个function的时候, 如果我写
AAA({"SSS"});
他报错说:
formal and actual do not have assignment compatible data types (expecting datatype compatible with 'queue of string' but found 'packed array' instead).
我应该怎么写?
Elements of dynamic arrays, queues, and associative arrays that are passed by reference may get removed
from the array or the array may get resized before the called function or task completes. The specific array
element passed by reference shall continue to exist within the scope of the called tasks or functions until they
complete. Changes made to the values of array elements by the called task or function shall not be visible
outside the scope of those tasks or functions if those array elements were removed from the array before the
changes were made. These references shall be called outdated references.
那如果变成了outdated reference会怎么样?
还有, 我怎么样直接传参数给一个"queue of string"
例如, 定义一个functionAAA, 参数为string的queue类型sq[$]
virtual function void AAA (string sq [$])
...
endfunction
调用这个function的时候, 如果我写
AAA({"SSS"});
他报错说:
formal and actual do not have assignment compatible data types (expecting datatype compatible with 'queue of string' but found 'packed array' instead).
我应该怎么写?
上面一大段英文应该说的是pass by reference的意思。method参数有二种传递方式:by value, by reference,定义为ref类型的参数就是by reference的,定义为input/output/inout的就是by value的。by reference的方式下,在method call内部对参数作改变,method call外部能立即反映出来。而by value的方式下,直到method call结束后才反映出来。上面英文提到,当使用by reference方式时,在method call内部删除数组时,外面可以立即看到数组被删除,而使用by value方式时,method call内部删除数组后,外面的数组仍存在,并没有被删除
.
{"SSS"}是一个数组吧,所以这样传递肯定是不行的,类型不一致。我也不知道怎么做强制类型转换直接传进去。
谢谢小编 分享
我理解这段话是说如果某个数组是by reference传进来的参数,如果相应的数组元素在外面已经被删除了,在函数或过程中依然可以看到,但这时对这些元素所做的修改已经无法再反映在函数或过程之外了。这种所谓过时的引用不是错误,但是可能引起逻辑功能上的意外。
问题1:使用ref进行引用传递类似于C中的指针参数。
问题2:没这样写过,不知道原因。我一般是这样进行动态数组和队列的参数传递:
string sq_new[$];
sq_new[0] = "SSS";
AAA(sq_new);