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.
Class methods and declared for loop variables are by default automatic,regardless of the lifetime attribute of the scope in which they are declared.
下面举个栗子:
task A();
int a;
B();
endtask
task B();
a = 1; //compile error
endtask
上述code中 a 是 task A的局部变量,所以task B无法对a进行操作。