quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif constant class members

Class properties can be made read-only by a const declaration like any other SystemVerilog variable. However, because class objects are dynamic objects, class properties allow two forms of read-only variables, global constants and instance constants.

   

space.gif

Global constant class properties include an initial value as part of their declaration. They are similar to other const variables in that they cannot be assigned a value anywhere other than in the declaration.

   

space.gif

Instance constants do not include an initial value in their declaration, only the const qualifier. This type of constant can be assigned a value at run time, but the assignment can only be done once in the corresponding class constructor.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example - class constants
   

space.gif


  1 `define PRINT task print (); \
  2    begin \
  3       $write("%s -> Size is %0d\n",this.name, this.Lsize); \
  4       $write("%s -> Size is %0d\n",this.name, this.Gsize); \
  5    end \
  6 endtask
  7 
  8 program class_constant;
  9   class A;
 10      const integer Gsize = 64; // constant value
 11      const integer Lsize;
 12      string name;
 13      // Constructor
 14      function new (string name);
 15        begin
 16          this.name = name;
 17          this.Lsize = 100; // only one assignment in new
 18        end 
 19      endfunction
 20      // This is not allowed
 21      task modify();
 22        begin
 23          // This is wrong 
 24          //this.Lsize ++; 
 25          // This is wrong 
 26          //this.Gsize ++; 
 27        end
 28      endtask
 29     
 30      `PRINT
 31    endclass
 32 
 33    A a;
 34 
 35    initial begin
 36      a = new("A");
 37      a.print();
 38    end
 39 
 40 endprogram
You could download file class_constant.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation - class constants
   

space.gif

 A -> Size is 100
 A -> Size is 64
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com