Hello! I’ve tried a program to see the working of static constraint while inheriting a normal constraint from another class. When I disable the static constraint, both the constraints have to be affected. But here when I disable the static constraint, the normal constraint is coming to constrain the values of a. Why?
Here is the code:
class packet1;
rand bit [4:0] a;
constraint c1 {a<15;}
endclass
class packet2 extends packet1;
static constraint c2{a>15;}
endclass
module class_in;
initial
begin
packet1 p1 = new;
packet2 p2 = new;
repeat (5)
begin
p1.randomize();
$display("a = %0d",p1.a);
end
$display("\n");
repeat(10)
begin
p2.c2.constraint_mode(0);
p2.randomize();
$display("\a = %0d",p2.a); //why is c1 not affected even though the static constraint c2 is disabled as it should be?
end
end
endmodule