The cast_assign() system function assigns values to variables that might not ordinarily be valid because of type checking rules.
Syntax : function integer cast_assign(scalar dest_var, scalar source_exp [,CHECK]);
When the cast_assign() system function is called without CHECK, the function assigns the source expression to the destination variable. If the assignment is illegal, a fatal runtime error occurs. When the cast_assign() system function is called with CHECK specified, the function makes the assignment and returns a 1 if the casting is successful. If the casting is unsuccessful, the function does not make the assignment and returns a 0.
EXAMPLE: class base {
virtualtask pri(){
printf(" BASE CLASS STATEMENT\n");
}
}
class EX_1 extends base {
task pri(){
printf(" EX1 CLASS STATEMENT\n");
}
}
program main{
base b;
EX_1 e1;
b = new();
if(cast_assign(e2,b))
printf("casting done \n");
else printf(" casting failed \n");
e2.pri();
printf(" END OF SIMULATION \n");
}
RESULTS:
casting done BASE CLASS STATEMENT END OF SIMULATION