我注意到SV LRM(1800-2012)7.12(数组操作方法)中的max()和min()函数有趣.我在虚拟SV文件中尝试了max()和min()函数
int a[3] = {0,5,5};
int q[$];
int b;
q = a.max(); // legal
b = a.max(); // illegal
Run Code Online (Sandbox Code Playgroud)
非法声明错误是
Incompatible complex type assignment
Type of source expression is incompatible with type of target expression.
Mismatching types cannot be used in assignments, initializations and
instantiations. The type of the target is 'int', while the type of the
source is 'int$[$]'.
Run Code Online (Sandbox Code Playgroud)
所以我评论了非法声明并进行了测试.它编译并运行正常,但我希望能够更深入地了解为什么函数返回队列而不是单个元素 - 我打印出q的内容和大小,但是大小仍然是1和5正在打印就一次.那种冗余然后使max()和min()函数返回队列?
Chris Spear和Greg Tumbush撰写的" SystemVerilog for Verification "一书在第2.6.2节中对此主题有一个很好的解释,我在下面引用它:
"数组定位器方法在一个解压缩的数组中查找数据.首先你可能想知道为什么这些数据返回一个值的队列.毕竟,数组中只有一个最大值.但是,当你提问时,SystemVerilog需要一个队列来自空队列或动态数组的值."