In reply to dave_59:
Class objects are always dynamically constructed. Class objects are constructed by the new() method and exist as long as at least one class variable has a handle to it. Class objects do not have storage lifetimes associated with a scope, but class variables that holds the handles may.
Automatic storage lifetimes are associated with entering and exiting procedural blocks such as functions, tasks, and named blocks. The default for variables declared in a procedural block outside of a class is to have a static lifetime. That also means the arguments and function return variable are also have static lifetimes by default.
Procedural blocks inside of classes (methods) can only have automatic lifetimes. This matches C/C++ semantics. Static methods, on the other hand, just mean the method is global to the class type and not specific to a particular class object; it has nothing to do with the storage lifetime of the variables declared inside that method.
Because of legacy Verilog which originally had no concept of automatic lifetimes, SystemVerilog had to keep the default lifetime static, but added an option to make all procedural blocks declared within a module/program/interface automatic. So when you declare a program as automatic, it only effects the defaults for variables declared within procedural blocks. Variables declared outside of a procedural block as well as outside a class always have a static lifetime.
By the way, I do not recommend using program blocks - just use modules. See Are Program Blocks Necessary? - Verification Horizons
Hi Dave,
I have a question and, some confusion here. Since you say that within a class all the methods(task/function) have automatic scope. Below is a code from one of the sequences and, this code snippet is within the task body() method.
class dummy
task body()
foreach (pm.cfg.sel_pid[idx]) begin
curr_pid = pm.cfg.sel_pid[idx];
exp_num_events = 1 + 1 + count[curr_pid] + num_recvq_entries + num_recvq_entries;
for(i=0; i<100; i++) begin
//Monitor HIFIS for the event write
fork
automatic longint eq_pa_r = eq_pa;
hiarb_hifis_req_chk(eq_pa_r,fxr_defs_pkg::Write,num_events);
join_none;
eq_pa = eq_pa + 'h40;
`ovm_info(get_type_name(), $sformatf("New EQ PA : %0x\n", eq_pa), OVM_NONE);
end
endtask
endclass
My Question here is then why I had to make the variable Automatic here since it was within the class. I ran into the problem where all the threads were sharing the same address. But this variable should have been default automatic right since it was in a method within the Class.
Please kindly clarify on this.