Global constraint for dynamic arrays

Hi,

why is the dynamic array “a” in the following example2 constructed without using explicitly new?

class RandArray; rand bit [5:0] a[];

constraint c {
a.size inside {[5:10]};
a[0] > 0;
foreach(a[i])
if (i > 0) a[i] > a[i-1];
}

endclass

module example2;
RandArray ra;
initial begin
ra = new();
assert(ra.randomize());
$display(“Random Array = “);
foreach (ra.a[i]) $display(”%6d”, ra.a[i]);
end
endmodule

In this example below i get an error. Why does this “automatic” object construction do not work in this case? The content of items will not be created here.

class transaction; rand bit [3:0] src, dst; endclass

class transaction_seq_defekt;

rand transaction items[]; 	

constraint c	{
	items.size() inside {[8:10]};		
	foreach(items[i])
		if(i > 0) items[i].dst > items[i-1].dst;
}

endclass

module example1;

transaction_seq_defekt seq_bad;		

initial	begin
	
        seq_bad = new();
	assert(seq_bad.randomize());		
	
	foreach(seq_bad.items[i])
		$display("item_bad[%0d] = %0d", i, seq_bad.items[i].dst);
	


end

endmodule
endmodule

If you have a rand array of objects, then during randomize() you can create an array of a random size, but the construction of the objects referenced by the array does not take place.

That’s why your first example works - it is of a bit type, whereas the second does not - it is of an object type.