Hi,
Can anybody explain me how can i use Exists method with multidimensional associative array?
Thanks in advance.
Hi,
Can anybody explain me how can i use Exists method with multidimensional associative array?
Thanks in advance.
In reply to cashah85:
SystemVerilog has arrays of arrays, not really multidimensional arrays. You need to check the dimensions one by one. You can do this with an if-tree, or use the short-circuit expression guards to prevent accessing non-existant elements.
module top;
int aa[int][int];
initial begin
$display(aa.exists(1) && aa[1].exists(2 )); // 0
aa[1][2] = 3;
$display(aa.exists(1) && aa[1].exists(2 )); // 1
aa[3][4] = 5;
$display(aa.exists(3) && aa[3].exists(3 )); // 0
$display(aa.exists(3) && aa[3].exists(4 )); // 1
end
endmodule
In reply to dave_59:
Hi Dave,
But what if there is another dimension in the above associative array. Then how to use the exists function.
For example:
module top;
int aa[int][int][int];
initial begin
aa[3][4][6] = 5;
$display(aa.exists(3) && aa[3].exists(4 ) && aa[3][4].exists(6 )); // this gives a compilation error " Error found while trying to resolve cross-module reference. token 'exists'."
end
endmodule
The above gives compilation error because of aa[3][4].exists(6 ). Please advice what am I doing wrong.
Thanks in advance
In reply to dave_59:
Hi Dave,
Yes, sorry I was trying to get the value (instead of key) using the exist function.
Your reply on Stack Overflow was quite helpful.
Thanks