zz8318
March 2, 2020, 2:32am
1
Here is my code. My question is how to set the default value to the parameter (my_item) ?
class my_item extends uvm_object;
rand bit mode;
rand bit enable;
rand bit [3:0] data;
constraint my_cons {
data[0] == 0;
}
endclass : my_item
task send(int num = 1, my_item item = ??);
...
endtask
In reply to zz8318 :
You didn’t say what you wanted the default to be. The only reasonable default in the case is null . Then inside you can construct a new item if it is null.
task send(int num = 1, my_item item = null);
if (item == null) item = new(); ...
...
endtask
zz8318
March 2, 2020, 12:57pm
3
In reply to dave_59 :
good to know. Thank you very much
In reply to dave_59 :
Never had the idea of mentioning a default value ( non-null ) for an object .
Is it possible ?
( Cos how would you create and initialize in the declaration itself , call another function ? )
In reply to MICRO_91 :
The SystemVerilog BNF does not allow you to call new() directly, but you could call a static method, like my_item::type_id::create() .
But I prefer using a mechanism like null that indicates whether the default was used or not.