# Static Method

**URL:** <https://verificationacademy.com/forums/t/static-method/30147>\
**Category:** UVM\
**Tags:** UVM, static-method\
**Created:** [November 19, 2014, 6:43pm UTC](https://verificationacademy.com/forums/t/static-method/30147 "2014-11-19T18:43:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthony.vu.gd-ais.com](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@anthony.vu.gd-ais.com](https://verificationacademy.com/forums/u/anthony.vu.gd-ais.com)\
**Post date:** [November 19, 2014, 6:43pm UTC](https://verificationacademy.com/forums/t/static-method/30147/1 "2014-11-19T18:43:03Z")

</div>

UVM Cookbook is a great tech reference; I appreciate your time and expertise creating it.  
I am reading spi\_env\_config.svh (TestbenchBuild/uvm\_tb\_build\_ss\_tb/tb\_build/sub\_system\_tbs/pss\_tb/env/pss\_env\_config.svh), but I could not understand how this line works:

extern static function pss\_env\_config get\_config( uvm\_component c);

1. A static method cannot access automatic properties; pss\_env\_config is not static. How can this work?
2. In this method, macro `uvm\_fatal is used. This is not “enabled” yet; how can this work?

Thanks.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [November 19, 2014, 7:09pm UTC](https://verificationacademy.com/forums/t/static-method/30147/2 "2014-11-19T19:09:24Z")

</div>

The only thing special about a static method is that is has no **this** handle. You cannot reference members of the class the method is defined. t is an automatic variable inside the scope of the get\_config() method, and a static method may access anything within its scope.

`uvm\_fatal will call the global uvm\_report\_fatal() function defined in the uvm\_pkg. It will not call this.uvm\_report\_fatal().

---

<div class="post-metadata">

**Author:** ![anthony.vu.gd-ais.com](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@anthony.vu.gd-ais.com](https://verificationacademy.com/forums/u/anthony.vu.gd-ais.com)\
**Post date:** [November 19, 2014, 8:39pm UTC](https://verificationacademy.com/forums/t/static-method/30147/3 "2014-11-19T20:39:40Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/static-method/30147/2):_

Many thanks for your speedy response; you’re great always.

1. The pss\_env\_config is the returned type; when memory is allocated for the static method pss\_env\_config::get\_config, this type is not created yet. Would it not result in “undefined type” during compilation?

2. As written in line 186 of the uvm\_globals.svh, the uvm\_globals::uvm\_report\_fatal is not a static method; an access to this automatic method in a static method will result a syntax error. In the old days, we used macro `uvm_fatal_context which uses static uvm_root::get to get around this issue. Has there been a new revision of the UVM, and this issue has been taken care of and there is no need for `uvm\_\*\_context?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [November 20, 2014, 12:40am UTC](https://verificationacademy.com/forums/t/static-method/30147/4 "2014-11-20T00:40:59Z")

</div>

_In reply to [TV](https://verificationacademy.com/forums/t/static-method/30147/3):_

1. This is called a self-referential type. Remember that when you declare a class variable, you are only declaring the space to hold a handle to a class object, not the class object itself. (Take my [short class on classes](https://blogs.sw.siemens.com/verificationhorizons/2013/07/16/class-on-classes/)). The compiler only needs to know that pss\_env\_config is going to be a type, it does not need a complete definition. As another example, the class uvm\_component has many self-referential types as well:

```verilog
class uvm_component extends uvm_report_object;
...
extern function new (string name, uvm_component parent);
uvm_component m_parent;
protected uvm_component m_children[string];
protected uvm_component m_children_by_handle[uvm_component];
...
endclass

```

1. The terminology of OOP is heavily overloaded. There is a difference between the **static** qualifier of a class method, and the **static** storage lifetime qualifier of a function. The storage lifetime (static or automatic) of a function is legacy from Verilog and does not apply to class methods which only have automatic lifetimes. See [this link](https://verificationacademy.com/forums/systemverilog/when-should-be-program-block-dynamic-or-static-members-static-program-block-members-automatic-program-blocks#answer-38825) for more info. A static method of a class can refer to anything that does not require a ‘this’ handle.

---

<div class="post-metadata">

**Author:** ![anthony.vu.gd-ais.com](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@anthony.vu.gd-ais.com](https://verificationacademy.com/forums/u/anthony.vu.gd-ais.com)\
**Post date:** [November 20, 2014, 5:29pm UTC](https://verificationacademy.com/forums/t/static-method/30147/5 "2014-11-20T17:29:54Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/static-method/30147/4):_

Great responses! I know that I’m gonna learn much from you any time I’d ask; really appreciate this; I agree with most of them.

1. Indeed the compile needs to know if a type exists; I must agree with your response on this principle. This is precisely why we sometimes do typedef class uvm\_component; etc.  
The point is a compile may not know what pss\_env\_config is until it is defined; therefore, the code as written may not work. More likely or not, it will result in a syntax error due to “undefined” type. For your example, the reason that uvm\_component works is that it is typedef’ed in its parent class uvm\_report\_object line 26.

2. Who knows and remembers all the terminologies of OOP all the time? Thanks a bunch to point it out :-) I completely agree with you about their loaded words!  
The key word “static” is not a legacy term; it is defined in all IEEE 1800’s including the IEEE 1800-2012 section 8.10 page 141. It is stated that “A static method has no access to non-static members (class properties or methods)”. Accessing a non-static method as shown in pss\_env\_config::get\_config will be a syntax error.  
The reason that `uvm_fatal_context works and `uvm\_fatal does not is that `uvm_fatal_context uses a static method but `uvm\_fatal does not.

The point of my inquiry is that the code as written will have at least a syntax error unless there is some clever trick hidden somewhere which I don’t know and would like to learn.  
In my humble opinion, the code would be fine if it would has been written as:  
1.  
typedef class pss\_env\_config;  
`include “pss_env_config.svh” These can be written in the package in which the pss_env_config.svh is `include’d.

1. `uvm_fatal_context should be used instead of `uvm\_fatal.

Thanks again; it is always a pleasure reading your posts; I am a big fan of yours.  
Best regards

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [November 20, 2014, 8:17pm UTC](https://verificationacademy.com/forums/t/static-method/30147/6 "2014-11-20T20:17:38Z")

</div>

_In reply to [TV](https://verificationacademy.com/forums/t/static-method/30147/5):_

1. A typedef is not required in this case because pss\_env\_config is known to be a type when it appears in the variable declaration **t**. The **class pss\_env\_config** in the line above takes care of that. The only time a typedef is absolutely required is when the compiler encounters a never before seen identifier. That happens when you have a pair of cyclic definitions: class A needs a handle to class B, and class B needs a handle to class A. You can only define one class first, the other will need a typedef. The other place you will see typedefs used is then the scripts used to compile code are lax in their compilation order. You will see a lot of that in the UVM.  
If you are getting a syntax error from the compilation of the pss\_env\_config.svh file, then show the error and let your vendor know they have a bug.
2. The key word in section 8.10 is _ **members** _. “A static method has no access to non-static **members** (class properties or methods)” It does have access to everything else visible within its scope. The functions uvm\_report\_enable() and uvm\_report\_fatal() are both defined in the package uvm\_pkg, they are not member class methods. So they are visible and accessible to the static method pss\_env\_config::get\_config. Had the class pss\_env\_config been extended from uvm\_component (which is extended from uvm\_report\_object), then there would be a legitimate syntax error. That is because uvm\_report\_object _does_ have class member methods named uvm\_report\_enable and uvm\_report\_fatal. Those non-static class methods names would be found first, hiding the functions defined at the top-level of the package.

---

<div class="post-metadata">

**Author:** ![CRVAddict](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ed8c4c/32.png) [@CRVAddict](https://verificationacademy.com/forums/u/CRVAddict)\
**Post date:** [March 11, 2020, 3:33am UTC](https://verificationacademy.com/forums/t/static-method/30147/7 "2020-03-11T03:33:10Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/static-method/30147/6):_

Hi Rich,

I got a follow-up question to this, I have a static function inside class extended from uvm\_sequence(so parent is uvm\_object not uvm\_component).

Inside the static function if i call 'uvm\_error i am getting a compile error

**[b]\*[b]Illegal to access non-static method ‘uvm\_report\_enabled’ from a static method.**  
_[/b][/b]_\*\*\*

I am not able to understand why, please enlighten me.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [March 11, 2020, 4:25am UTC](https://verificationacademy.com/forums/t/static-method/30147/8 "2020-03-11T04:25:56Z")

</div>

_In reply to [CRVAddict](https://verificationacademy.com/forums/t/static-method/30147/7):_

This is because **uvm\_sequence\_item** has its own [reporting interface](https://verificationacademy.com/verification-methodology-reference/uvm/docs_1.1b/html/files/seq/uvm_sequence_item-svh.html#uvm_sequence_item.Reporting_Interface). It delegates to the sequencer the sequence is running on, or the uvm\_top if the sequencer is null (virtual sequence)

You need to use [`uvm\_info\_context](https://verificationacademy.com/verification-methodology-reference/uvm/docs_1.1c/html/files/macros/uvm_message_defines-svh.html#uvm_info_context) to provide some context for reporting. Without knowing why you need a static method, I can only suggest using uvm\_root::get() as the context

---

<div class="post-metadata">

**Author:** ![CRVAddict](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ed8c4c/32.png) [@CRVAddict](https://verificationacademy.com/forums/u/CRVAddict)\
**Post date:** [March 11, 2020, 3:17pm UTC](https://verificationacademy.com/forums/t/static-method/30147/9 "2020-03-11T15:17:48Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/static-method/30147/8):_

I am trying to access some methods inside the seq without instantiating it
