for a simple code
-------code-----------
class A; endclass
module top;
initial begin
A a = new();
end
endmodule
on compilation may give u a message
like “a is implicitly static you must explicitly declare it as static or automatic or separate out deceleration and initialization of ‘a’”
from the message what it says 3 solutions can be
“static A a = new();”
“automatic A a = new();”
“A a;
a = new();”
I am curious what differences with ‘a’ being static or automatic?
[2014-05-15 08:12:45 UTC] vlib work && vlog -writetoplevels modelsim.tops ‘-timescale’ ‘1ns/1ns’ ‘-mfcu’ ‘+acc=rmb’ ‘-sv’ ‘-suppress’ ‘2181’ design.sv testbench.sv && vsim -c -do “onElabError resume; run -all; exit” -f modelsim.tops ‘-suppress’ ‘3829’
Model Technology ModelSim ALTERA vlog 10.1d Compiler 2012.11 Nov 2 2012
**** Warning: design.sv(6): (vlog-LRM-2244) Variable ‘a’ is implicitly static. You must explicitly declare it as static or automatic.**
– Compiling package design_sv_unit
– Compiling module top
**** Warning: design.sv(6): (vlog-LRM-2244) Variable ‘a’ is implicitly static. You must explicitly declare it as static or automatic.**
Top level modules:
top
Reading /altera-quartus/13.1/modelsim_ase/tcl/vsim/pref.tcl
10.1d
vsim -do {onElabError resume; run -all; exit} -c -suppress 3829 top
See Section 6.21 Scope and lifetime of the 1800-2012 LRM. Your confusion (as well as many other people’s) with this is main reason the LRM requires an error message.
Static vs. automatic is manly a difference in lifetime, but also initialization. Static variables initialize before time 0, and automatic variable initialize when the block is procedurally activated.
In most programming languages, variables declared inside of procedural blocks are automatic by default, but in Verilog, the default is static. SystemVerilog was able to change the default for class methods to match C/C++, but could not do it for backward compatibility with legacy Verilog blocks.
Variable initialization was a relatively new feature in Verilog, but so many people missed the fact that when they declared a variable inside a procedural looping construct, the variable only got initialized once at time 0, not each iteration of the loop.
module top;
initial repeat (10) begin
A a = new();
end
endmodule