Static vs automatic task/function — explain with an example
Static vs automatic task/function — explain with an example
Model answer
Default lifetime: tasks/functions in a **module** are static; those in a **class** are automatic. Variables inherit the lifetime of the task unless you write static or automatic on the variable itself. verilog module lifetime_example; task static inc_static(); static int cA; automatic int cB; int cC; // static, inherited cA++; cB++; cC++; $display("static task : A=%0d B=%0d C=%0d", cA, cB, cC); endtask verilog initial begin repeat (3) inc_static(); repeat (3) inc_auto(); end endmodule Output: {|l|c|c|c|}\hline Call & cA & cB & cC\\ \hline static task, call 1 & 1 & 1 & 1\\ \hline static task, call 2 & 2 & 1 & 2\\ \hline static task, call 3 & 3 & 1 & 3\\ \hline automatic task, call 1 & 1 & 1 & 1\\ \hline automatic task, call 2 & 2 & 1 & 1\\ \hline automatic task, call 3 & 3 & 1 & 1\\ \hline Automatic variables cannot be accessed by hierarchical reference.