2D Unconstrained Nx1 Array

若如初见. 提交于 2019-12-29 09:29:04

问题


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

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


回答1:


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

Strange behavior, indeed.




回答2:


The LRM (section 9.3.3 Aggregates) states:

Aggregates containing a single element association shall always be specified using named association in order to distinguish them from parenthesized expressions.

So, this is OK:

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

and this is not:

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

http://www.edaplayground.com/x/6a4



来源:https://stackoverflow.com/questions/35359413/2d-unconstrained-nx1-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!