Default null for dynamic virtual interface array in the method parameter list

Hi,

I have a couple of syntactic related questions here now. Both of them can be illustrated with the following code example.

  1. 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?
  2. 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 the answers!

-ilia

In reply to ilia:

Few modification to your code and it works

interface test_if;
endinterface : test_if
class test_class;
endclass : test_class
function automatic int test_func(test_class classes[], virtual interface test_if ifs[] = {});
  if (classes.size() == 0)
    return 0;
  else
    return 1;
endfunction : test_func
module main();
  test_class cls_arr[];
  bit ret;
  initial begin
    ret = test_func(cls_arr);
    $display("ret:%0d",ret);
  end
endmodule

In reply to rohitk:

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?

-ilia

In reply to ilia:

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.

In reply to dave_59:

Dave,

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?

..., virtual interface test_if ifs[] = null);

Again, thanks already in advance for your reply!

-ilia

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
.