systemverilog 參數化類及與靜態關係__sytemverilog

來源:互聯網
上載者:User

以兩個例子說明參數化類別及聲明靜態變數時的情況:

eg:

program param_stack;
class stack #(type T = int);
  int m_cnt;
  static int counter = 2;
 
  function new;
    m_cnt = counter++;
  endfunction: new 
 
endclass: stack

class stacked extends stack #(real);
 
endclass: stacked


typedef stack #(byte) stack_byte;
typedef stack #() stact_int;


 stack_byte S1 = new();
  stack_byte S2 = new();
  stack S3 = new();
  stack #(bit) S4 = new();
  stacked S5 = new();


initial begin 
  $display ("Counter value of S1 instance = %0d", stack #(byte)::counter);
 $display ("Counter value of S2 instance = %0d", stack_byte:: counter);
 $display ("Counter value of S3 instance = %0d", stack #()::counter);
 $display ("Counter value of S4 instance = %0d", stack#(bit)::counter);
 $display ("Counter value of S5 instance = %0d", stacked::counter);
end
 
endprogram: param_stack

列印的值依次為:

3

4

3

3

3

解釋:雖然靜態變數只會存在一個副本。

由於S1和S2均由stack_byte建立,所以S1時counter的值為3,S2為4;

S3則是由預設參數類建立,等同於程式中的stack_int,counter值為3;

S4則是type為bit的類建立,counter同樣為3;

S5亦然。

即當參數類的參數不同時,他們是不同的類。

註:

需要注意參數化類引用靜態變數的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.