Static task and automatic task

class a;
  static int b;
  task c(); // then with static task c()
   b++;
   $display (b) ;
  endtask
endclass

in the above mention code for both static task and task i’m getting same output . what is the different please anyone explain me ?

In reply to rkrajan96:
Please read http://sscce.org/ and then see what is the exact difference between static tasks/functions and automatic tasks/functions ? please explain with a clear example | Verification Academy

1 Like

In reply to dave_59:
Thanks for that explaining .But I cannot able to relate with my example . Why for me output is same would you please explain with that ??

In reply to rkrajan96:

How about explaining why you expect different results.

In reply to rkrajan96:

Here is static class method definition in SystemVerilog LRM. In your example, you won’t see result difference between non-static class method task c() and static class method static task c(). I think you may need to differ the concept between a static method and the task with the static lifetime as well.

  1. Classes
    8.10 Static methods
  • Methods can be declared as static.
  • A static method is subject to all the class scoping and access rules, but behaves like a regular subroutine that can be called outside the class, even with no class instantiation.
  • A static method has no access to non-static members (class properties or methods), but it can directly access static class properties or call static methods of the same class.
  • Access to non-static members or to the special this handle within the body of a static method is illegal and results in a compiler error
  • Static methods cannot be virtual.

A static method static task c() is different from a task with static lifetime task [lifetime] c(). The former refers to the lifetime of the method within the class, while the latter refers to the lifetime of the arguments and variables within the task.

[lifetime] can be static or automatic. The methods Tasks defined within a class are always automatic

In reply to Lina.Lin:

Thanks for bro . I got to know now . Thanks for your valuable response