Arrays 二维无约束Nx1阵列

Arrays 二维无约束Nx1阵列,arrays,vhdl,Arrays,Vhdl,我正在尝试创建一个灵活的常量数组。我想使用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 down

我正在尝试创建一个灵活的常量数组。我想使用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_数组是整数的数组(整数范围,整数范围);
常数M:正:=2;
常数nMax:正:=1;
常数n:int_2d_数组(M-1向下到0,nMax-1向下到0):=((1)、(2));--错误的
错误:类型int_2d_数组与整数文本不匹配
如果我这样做,它不会抱怨:

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
type int_2d_数组是整数的数组(整数范围,整数范围);
常数M:正:=2;
常数nMax:正:=2;
常数n:int_2d_数组(M-1向下到0,nMax-1向下到0):=((0,1)、(2,2));--认可的

第一个示例甚至可以使用2D数组吗?

我用以下难看的方式编译了第一个示例:

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) := ( (others => 1) , (others => 2) ); 
type int_2d_数组是整数的数组(整数范围,整数范围);
常数M:正:=2;
常数nMax:正:=1;
常数n:int_2d_数组(M-1向下到0,nMax-1向下到0):=((其他=>1),(其他=>2));

确实是奇怪的行为。

我设法用以下丑陋的方式编译了第一个示例:

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) := ( (others => 1) , (others => 2) ); 
type int_2d_数组是整数的数组(整数范围,整数范围);
常数M:正:=2;
常数nMax:正:=1;
常数n:int_2d_数组(M-1向下到0,nMax-1向下到0):=((其他=>1),(其他=>2));
的确是奇怪的行为。

LRM(第9.3.3节)规定:

包含单个元素关联的聚合 应始终使用命名关联来指定,以便将其与括号中的表达式区分开来

所以,这没关系:

constant n : int_1d_array(0 downto 0) := ( 0 => 1 );
这不是:

constant n : int_1d_array(0 downto 0) := ( 1 );
LRM(第9.3.3节骨料)规定:

包含单个元素关联的聚合 应始终使用命名关联来指定,以便将其与括号中的表达式区分开来

所以,这没关系:

constant n : int_1d_array(0 downto 0) := ( 0 => 1 );
这不是:

constant n : int_1d_array(0 downto 0) := ( 1 );

您的答案不使用模型编译您的答案不使用模型编译谢谢您提供了更开明的评论谢谢您提供了更开明的评论