首页 > 解决方案 > 如何在 VHDL 中初始化记录数组?

问题描述

我正在初始化一个记录数组,其中还包含一个字符串。我收到错误 HDLCompiler:806 第 109 行:“text_passages”附近的语法错误(下面代码中的最后一行)。初始化的正确方法是什么?

type text_info is
    record
        text : string(1 to 15);
        x: integer;
        y: integer;
    end record;
constant init_text_info: text_info := (text => "               ", x => 0, y => 0);
type text_info_array is array(natural range <>) of text_info;

我的声明和初始化如下

signal text_passages : text_info_array(0 to 1) := (others => init_text_info);
text_passages(0) <= (text => "This is a Test.", x => 50, y => 50);

标签: arraysvhdlrecord

解决方案


好吧,你在最后一行的末尾有一个额外的括号,但除此之外,没关系。(我怀疑您报告的错误消息是由该括号引起的。)最后一行应该是:

text_passages(0) <= (text => "This is a Test.", x => 50, y => 50);

一个 [MCVE]:

entity E is
end entity ;

architecture A of E is

  type text_info is
    record
        text : string(1 to 15);
        x: integer;
        y: integer;
    end record;
  constant init_text_info: text_info := (text => "               ", x => 0, y => 0);
  type text_info_array is array(natural range <>) of text_info;
  signal text_passages : text_info_array(0 to 1) := (others => init_text_info);

begin

  text_passages(0) <= (text => "This is a Test.", x => 50, y => 50);

end architecture A;

https://www.edaplayground.com/x/4ARJ

(最好提交 MCVE。)


推荐阅读