我正在初始化一个记录数组,其中也包含一个字符串。我收到错误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);
答案 0 :(得分:2)
好吧,您在最后一行的末尾有一个额外的括号,但是除此之外,还可以。 (我怀疑您报告的错误消息是由该括号引起的。)最后一行应该是:
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。)