如何在VHDL中初始化长度为1的数组

时间:2018-02-10 21:20:14

标签: arrays vhdl literals ghdl

我正在拼命尝试在VHDL中分配一个长度为1的数组的常量,但它似乎不起作用(使用GHDL),它抱怨我无法分配一个字面值数组内部的类型,进入数组。

package test is
    constant length : integer := 1; -- this could come from a different package

    type integer_array is array ((length - 1) downto 0) of integer;

    constant my_array : integer_array := (1);
end test;

当我尝试使用GHDL编译时,我收到错误消息test.vhdl:8:46:error: can't match integer literal with type array type "integer_array"

如果我将length更改为2并使用(1, 2)作为字面值,则效果非常好。

那么如何初始化长度为1的数组?

1 个答案:

答案 0 :(得分:0)

我找到了办法,但都不太理想:

使用显式索引

package test is
    constant length : integer := 1; -- this could come from a different package

    type integer_array is array ((length - 1) downto 0) of integer;

    constant my_array : integer_array := (0 => 1);
end test;

使用others

package test is
    constant length : integer := 1; -- this could come from a different package

    type integer_array is array ((length - 1) downto 0) of integer;

    constant my_array : integer_array := (1, others => 0);
end test;

虽然我仍然希望有更好的方法。