I have a couple of syntactic related questions here now. Both of them can be illustrated with the following code example.
Is it legal to put default null for dynamic virtual interface array in the function parameter list? What is the correct syntax in SV LRM?
How could I check easily if the dynamic array of objects is null? I think the syntax of the check classes == null in the following example will not work. Should I use e.g. classes.size() etc?
interface test_if;
endinterface : test_if
class test_class;
endclass : test_class
function void test_func(test_class classes[], virtual interface test_if ifs[] = null);
if (classes == null)
return;
...
endfunction : test_func
Thanks for putting your explanation in that example. Your explanation is mostly fine for me. I am still thinking my 1) question i.e is syntactically somehow legal to put default null for the dynamic virtual interface array in the parameter list regarding to the SV LRM? Anyone to answer that?
The LRM only mentions that the singular data types: class, event, chandle, and virtual interface allow assignment or comparison to
null. The LRM does not mention everything that is illegal.
So based on your explanation why isn’t the following syntax working? Obviously, you just cannot directly assign null to array type of virtual interface variable, right? How should I do it then, only option is as rohitk stated?
In reply to ilia:
An array is an aspect of a type and is dealt with independently of the type of each element.
You could write
..., virtual interface test_if ifs[] = {null});
Which reads "
ifs is argument that is a dynamic array whose element type is
virtual interface test_if, and has a default value of one element, and that element’s value is
null.