参数化Class中的静态属性

static属性一般是在编译的时候就已经分配了内存,并被这个类的所有实例共享,
也就是在仿真时刻0之前就已经完成了静态属性的内存分配。
但是,参数化类中的静态属性可能有所区别。参数化类中的静态属性(参数化)是在参数初始化的时候才会分配。
// class with parameters class with_param #(type t = int); static t static_with_p; endclass // class without parameters class without_param; static int static_wo_p; endclass module top; initial begin $display(static_wo_p = %0d, without_param :: static_wo_p); $display(static_with_p = %0d, with_param :: static_with_p); end endmodule: top  
在上面的两个class中,一个包含parameter (with_param),还有一个不包含parameter(without_param).
在各自class中,我们都声明了静态属性。在访问静态属性“static_wo_p”时没有问题,而在访问静态属性
“static_with_p”时,编译器会报错(error或者warning):
warning-[pcsrmio] class scope used outside of classtestbench.sv, 59with_param::static_with_pan unspecialized class scope '::' reference was seen. to accessa static member of the default specialization outside the class'with_param', use 'with_param#( )::' instead. this will be anerror in a future release.  
需要修改成下面这样的写法才能编译通过。
$display(static_with_p = %0d, with_param # ( ) :: static_with_p);  
下面这个例子更能够展示参数化类中的静态属性和非参数类中的静态属性的区别:
class with_param #(type t = int);static t counter = 2;function new;counter++;endfunction: newendclass: with_paramclass with_param_extend extends with_param #(real);endclass: with_param_extendtypedef with_param #(byte) s_byte;s_byte s1 = new( );s_byte s2 = new( );with_param s3 = new( );with_param #(bit[2:0]) s4 = new( );with_param_extend s5 = new( );initial begin$display (counter value of s1 instance = %0d, with_param #(byte)::counter);$display (counter value of s2 instance = %0d, s_byte:: counter);$display (counter value of s3 instance = %0d, with_param #()::counter);$display (counter value of s4 instance = %0d, with_param #(bit[2:0])::counter);$ d i s p l a y ( c o u n t e r value of s5 instance =%0d,with_param_extend::counter);end  
仿真log:
counter value of s1 instance = 4counter value of s2 instance = 4counter value of s3 instance = 3counter value of s4 instance = 3counter value of s5 instance = 3.000000 v c s s i m u l a t i o n r e p o r t  
上面的例子中s1、s2、s3、s4、s5中的参数t分别被覆盖成byte、byte、int、bit[2:0]、real,所以只有s1(s_byte)和s2(s_byte)中的静态属性counter彼此共享。
参数类的扩展类
class class1 #(type t = int); ….endclass class class2 #(type p = real) extends class1;class class3 #(type p = real) extends class1 #(integer);class class4 #(type p = real) extends class1 #(p);  
上面是一个参数化类的扩展类示例,class1是一个参数化类,参数t默认为int。
class2增加了一个参数p,此时参数t为默认的int
class3增加了一个参数p,此时参数t覆盖成integer
class4增加了一个参数p,此时参数t也覆盖成为p

亲眼见证由海尔黑科技产品为您打造的真正浴室世界
智慧太阳能路灯生产厂家排名榜前十名都有哪些?
华为何刚透露MateX将挑战单月10万台以上的产量 并认为2299欧元的价格还是比较合理的
格创东智亮相2018中国工业互联网大会,获颁广东省工业互联网应用标杆证书
LC电路类型和特性
参数化Class中的静态属性
解读非洲:了解非洲各个国家的风电光伏比例
华为或向高通购5000万个处理器_任正非回应总部深圳搬迁的传闻
生物识别技术第一代和二代的区别
Gosund于推出中规智能插座,加速国内市场的布局
一种基于全电介质紧凑薄膜结构的计算重构微型光谱仪
磷酸铁锂电池组供电系统在变电站的应用
AXI实战(一)-搭建简单仿真环境
通过简单的保存-恢复策略避免UVM VIP的冗余仿真周期
浅谈产品电磁兼容性设计培训的重要性
旧手机别丢了!参与vivo以旧换新活动, 最高可享2020元补贴
如何用两种不同的方法列写双容水槽传递函数
电路板设计可测试性技术
怎么解决C语言中的内存泄漏问题呢?
基于对数放大器进行RF脉冲检测的作用分析