- Static members of a parameterized class are not static across specializations of that class
Example
Class A#(int size = 4)
Typedef A(5) B
Typedef A(6) C
B is a specialization of A
C is a specialization of A
If there is a static variable called my_static in class A, Classes B and C have a separate copy of my_static
If my_static is inteded to be static across classes B and C then it should be declared static in a non-parameterized class and class A should be extended from that class.
- What is the syntax when we define functions that belong to a parameterized class outside the class body
class C #(int p = 1, type T = int);
extern static function T f();
endclass
function C::T C::f();
return p + C::p;
endfunction
class C #(int p = 1);
parameter int q = 5; // local parameter
static task t;
int p;
int x = C::p; // C::p disambiguates p
// C::p is not p in the default specialization
endtask
endclass
int x = C::p; // illegal; C:: is not permitted in this context
int y = C#()::p; // legal; refers to parameter p in the default
// specialization of C
typedef C T; // T is a default specialization, not an alias to
// the name “C”
int z = T::p; // legal; T::p refers to p in the default specialization
int v = C#(3)::p; // legal; parameter p in the specialization of C#(3)
int w = C#()::q; // legal; refers to the local parameter
T obj = new();
int u = obj.q; // legal; refers to the local parameter
bit arr[obj.q]; // illegal: local parameter is not a constant expression
- If you have a class definition like this:
- Class Env#(type T = int);
- Class Env1 extends Env#(bit)
- Case 1:
- Env#(bit) Envbit;
- Envbit = Env#(bit)::type_id::create(“Envbit”, this);
- Env1 env1;
- Envbit = Env1::type_id::create(“Env1”, this);
- Though seemingly the types of Envbit and Env1 are same they are still considered two different class types.