2D Unconstrained Nx1 Array

后端 未结 2 1467
小蘑菇
小蘑菇 2020-12-21 18:41

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         


        
相关标签:
2条回答
  • 2020-12-21 19:10

    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

    0 讨论(0)
  • 2020-12-21 19:35

    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.

    0 讨论(0)
提交回复
热议问题