2D无约束Nx1阵列 [英] 2D Unconstrained Nx1 Array

查看:78
本文介绍了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) ); 

确实是奇怪的行为.

这篇关于2D无约束Nx1阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆