如何传递等于零integer_vector的空值length?(= 空数组)
背景:
\n在测试平台内,我\xc2\xb4d喜欢对不同类型的事务使用一个过程。像这样的东西:
\nentity foo is\nend entity foo;\n\narchitecture bar of foo is\n procedure Transaction (\n constant RX_BYTES : integer_vector\n ) is\n begin\n report "RX_BYTES\'length = " & to_string(RX_BYTES\'length);\n end procedure;\nbegin\n\n Transaction(RX_BYTES => ""); -- it\xc2\xb4s about this line\n\nend architecture bar;\nRun Code Online (Sandbox Code Playgroud)\n我有这样的想法,但这不起作用:
\nTransaction(RX_BYTES => "");\nRun Code Online (Sandbox Code Playgroud)\n模型模拟错误:
\n** Error: C:/Users/sbuhrow/Desktop/NULL_Vector.vhd(13): (vcom-1600) No feasible entries for subprogram "Transaction".\nRun Code Online (Sandbox Code Playgroud)\n
只需使用一个空范围:
Transaction(RX_BYTES => (1 to 0 => 0), ...);
Run Code Online (Sandbox Code Playgroud)
演示:
$ cat foo.vhd
entity foo is
end entity foo;
architecture bar of foo is
procedure p(constant c: integer_vector) is
begin
report "c'length = " & to_string(c'length);
end procedure p;
begin
p(c => (0 downto 1 => 0));
end architecture bar;
$ ghdl -a --std=08 foo.vhd
$ ghdl -r --std=08 foo
foo.vhd:7:5:@0ms:(report note): c'length = 0
Run Code Online (Sandbox Code Playgroud)
注意:如果您经常使用这样的空整数向量,您也可以声明一个常量:
constant empty_iv: integer_vector := (1 to 0 => 0);
Run Code Online (Sandbox Code Playgroud)
并在任何需要的地方使用它。