Initial values
in SystemVerilog are not constrained to simple
constants; they can include run-time expressions, including dynamic memory
allocation. For example, a static class handle or a mailbox can be created and
initialized by calling its new method (see Annex 11.4 Section 13.3.1), or static variables can be initialized
to random values by calling the $urandom
system task. This requires a
special pre-initial pass at run-time.
SystemVerilog adds an optional qualifier to specify the
default lifetime of all variables declared in task, function or block defined within
a module, interface or program (see Section 16). The lifetime qualifier is automatic or static. The
default lifetime is static.
program automatic test ;
int i; // not within a procedural block - static
task foo( int a ); //
arguments and variables in foo are automatic
...
endtask
endmodule
Class methods and declared for loop variables are by default automatic, regardless of the
lifetime attribute of the scope in which they are declared. Classes are
discussed in Section 11.
Note that automatic or
dynamic variables cannot be written with nonblocking or
continuous assignments. Automatic variables and dynamic constructs—objects
handles, dynamic arrays, associative arrays, strings, and event variables—
shall be limited to the procedural context.