【问题标题】:2D Unconstrained Nx1 Array二维无约束 Nx1 阵列
【发布时间】: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

第一个例子甚至可以使用二维数组吗?

【问题讨论】:

    标签: arrays vhdl


    【解决方案1】:

    LRM(第 9.3.3 节聚合)指出:

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

    所以,这没关系:

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

    这不是:

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

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

    【讨论】:

    • 感谢更多开明的评论
    【解决方案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) ); 
    

    确实是奇怪的行为。

    【讨论】:

    • 你的答案不能用 ModelSim 编译
    猜你喜欢
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 2012-04-01
    相关资源
    最近更新 更多