1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| // Static vs. Automatic storage
//
// In Verilog 1995, storage was static. So, a variable in functions or tasks would exist in a single space in memory, and exist throughout a simulation.
//
// Since Verilog 2001, we can use the 'automatic' keyword (so the stack is used for local variables). Now, variables can be unique for each scope.
// See 1800-2012.pdf SystemVerilog LRM Section 6.21 "Scope and lifetime".
//
module top;
static int module_int; // by default is static
class my_class;
static int class_int; //automatic by default
endclass
my_class class1, class2;
initial begin
class1=new();
class2=new();
$display("module_int:%0d",module_int);
$display("my_class::class_int:%0d",my_class::class_int);
my_class::class_int = 12;
$display("my_class::class_int:%0d class1.class_int:%0d class2.class_int:%0d",my_class::class_int, class1.class_int, class2.class_int);
class1.class_int = 14;
$display("my_class::class_int:%0d class1.class_int:%0d class2.class_int:%0d",my_class::class_int, class1.class_int, class2.class_int);
class2.class_int = 16;
$display("my_class::class_int:%0d class1.class_int:%0d class2.class_int:%0d",my_class::class_int, class1.class_int, class2.class_int);
$display("",);
end
endmodule
|