Hi, I have a struct defined as a member of another struct, but somehow I cannot read the correct member of each struct as expected. The code is as:
typedef struct {
string gender;
logic [ 4:0] start;
logic [ 4:0] ends;
int age;
} studentInfoT;
typedef struct {
string className;
logic [32-1:0] classLocation;
int classStudent;
studentInfoT memberInfo[string];
} classInfoT;
module test;
classInfoT classes[3] = '{
'{"A1", 32'h0000_0004, 32, '{
"PETER" : '{"Male " , 0, 31, 12},
"ANNE" : '{"Female " , 0, 0, 13}
}}
, '{"A2", 32'h0000_0002, 31, '{
"AMANDA" : '{"Female " , 0, 0, 14},
"DAVID" : '{"Male " , 31, 31, 12}
}}
, '{"B1", 32'h0000_0001, 45, '{
"TOM" : '{"Male " , 0, 0, 13},
"BROWNY" : '{"Female " , 31, 31, 14}
}}
};
initial begin
foreach (classes[i]) begin
$display("Class %0s -- %p", classes[i].className, classes[i]);
$display("--------------------------------------------------");
foreach (classes[i].memberInfo[s]) begin
$display("Student name: %0s --> %p", s, classes[i].memberInfo[s]);
end
$display("----------------------------------------------------------------------------------------------------\n");
end
end
endmodule: test