2

我拼命尝试在 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 的数组呢?

4

1 回答 1

1

我找到了方法来做到这一点,两者都不太理想:

带显式索引

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;

虽然我还是希望有更好的办法。

于 2018-02-10T21:35:37.993 回答