Monday, 7 December 2015

Static Variable Example

class test; 
  static int count=0;
  int id;
 
  function new();
    id=count++;
  endfunction
 
endclass


module test1;
  test t1;
 
  initial
    begin
      for(int i=0;i<5;i++)begin
        t1=new;
        $display("id : %0d , count : %0d",t1.id,t1.count);
      end     
    end
 
endmodule


OUTPUT:
id : 0 , count : 1
id : 1 , count : 2
id : 2 , count : 3
id : 3 , count : 4
id : 4 , count : 5



No comments:

Post a Comment