1

如果我有 2D 整数队列,我希望能够像这样内联声明它:

int my_queue[$][$] = {{1, 2}, {3, 4}};

我也看过

typedef int int_queue[$];
int_queue my_queue[$] = {{1, 2}, {3, 4}};

相反,当我编译时,VCS 为我提供了一个不兼容的复杂类型错误:

  Type of source expression is incompatible with type of target expression. 
  Mismatching types cannot be used in assignments, initializations and 
  instantiations. The type of the target is 'int$[$][$]', while the type of 
  the source is 'bit[63:0]'.

这对我来说意味着 VCS 期望等式的右侧能够正确转换。我一直在使用的解决方法是:

typedef int int_queue[$];
typedef int_queue int_queue_of_queues[$];
int_queue_of_queues my_queue = int_queue_of_queues'{{1, 2}, {3, 4}};

但这为 N 维添加了 N 个额外的 typedef 和行,我宁愿在一行中执行此操作。如果我有办法在没有 typedef 的情况下转换声明的右侧,那么这很简单,但我不知道这是否可能。

4

1 回答 1

2

数组连接语法仅适用于单个维度。您不能嵌套 {},因为在数组 {} 和整数 {} 连接之间存在歧义的情况下。您需要在外部或两个维度中使用数组分配模式。我更喜欢对两个维度都使用分配模式,从而更清楚地表明这些是数组元素,而不是整数连接。

int my_queue[$][$] = '{'{1, 2}, '{3, 4}};

请参阅 IEEE 1800-2017 LRM 中的第 10.10 节未打包数组串联。

于 2020-02-15T22:21:19.337 回答