【发布时间】:2016-02-12 09:50:33
【问题描述】:
我正在尝试创建一个灵活的常量数组。我想使用 2D 数组,有时可能是 2x1、2x2、3x2 数组等。例如:
type int_2d_array is array (integer range<>, integer range<>) of integer;
constant M : positive := 2;
constant nMax : positive := 1;
constant n : int_2d_array(M - 1 downto 0, nMax - 1 downto 0) := ( (1) , (2) ); -- wrong
error: type int_2d_array does not match with the integer literal
如果我这样做,它不会抱怨:
type int_2d_array is array (integer range<>, integer range<>) of integer;
constant M : positive := 2;
constant nMax : positive := 2;
constant n : int_2d_array(M - 1 downto 0, nMax - 1 downto 0) := ( ( 0,1 ) , ( 2,2 )); -- accepted
第一个例子甚至可以使用二维数组吗?
【问题讨论】: