2D无约束Nx1阵列

2D无约束Nx1阵列

问题描述:

我正在尝试创建一个灵活的常量数组.我想使用2D数组,有时可能是2x1、2x2、3x2数组等.例如:

I'm trying to create a flexible array of constants. I want to use a 2D array which may sometimes be for example a 2x1, 2x2, 3x2 array etc. For example:

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

如果我这样做,它不会抱怨:

If I do this, it doesn't complain:

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

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

Is the first example even possible using a 2D array?

我设法通过以下丑陋的方式来编译第一个示例:

I managed to compile the first example in the following ugly way:

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) ); 

确实是奇怪的行为.