reference:
IEEE 1800 6.21 Scope and lifetime
1. SV is stored in the variable
-
Variables declared outside a module, program, interface, checker, task, or function are local to the
compilation unit and have a static lifetime (exist for the whole simulation).
-
Variables declared inside a module, interface, program, or checker, but outside a task, process, or function, are local in scope(局部有效) and have a static lifetime.
-
Variables declared inside a static task, function, or block are local in scope and default to a static lifetime.
-
The Tasks and Functions On May BE declared AS automatic . The Variables declared in AN automatic Task, function, or Block are local in scope, default to The Lifetime of The Call or Block (lifetime variable automatic type function call time or a block statement life cycle), and ON are initialized to the each entry or at The Call Block.
-
An automatic block is one in which declarations are automatic by default. Specific variables within an automatic task, function, or block can be explicitly declared as static. Such variables have a static lifetime.
On the front of the three is a meaning, variables are static storage area exists, if there are multiple threads simultaneously calling task or function, task or function Mainland variables are shared, this problem occurs.
It is meant a two behind, there is a dynamic variable storage region, each call is assigned to the dynamic memory area of the task or function to store variables, executing the task or function to automatically release the dynamic memory.
1800 examples
module top_legal; int svar1 = 1; // static keyword optional initial begin for (int i=0; i<3; i++) begin automatic int loop3 = 0; // executes every loop for (int j=0; j<3; j++) begin loop3++; $display(loop3); end end // prints 1 2 3 1 2 3 1 2 3 for (int i=0; i<3; i++) begin static int loop2 = 0; // executes once at time zero for (int j=0; j<3; j++) begin loop2++; $display(loop2); end end // prints 1 2 3 4 5 6 7 8 9 end endmodule : top_legal top_illegal Module1; // Should Not the compile Initial the begin int svar2 = 2; // static / Automatic needed to Show Intent for (int I = 0; I <. 3; I ++) the begin int Loop3 = 0; // Illegal Statement for (int I = 0; I <. 3; I ++) the begin Loop3 ++; $ the display (Loop3); End End End endmodule: top_illegal // fact int loop3 = 2, without static do not add automatic output is 12,312,312 3; I do not know why the above is illegal statement
note:
Class methods (see Clause 8) and declared for loop variables (see 12.7.1) are by default automatic,regardless of the lifetime attribute of the scope in which they are declared.
Class methods and variables in the loop for default type is automatic, which is above should Why not add automatic output also reasons 23,123,123 of 1 bar.