What you practice
local and static members (2.5). Use static and local members to share state and hide internal class data. It is in Classes & OOP Basics — Part 2 · Verification & OOP of the SystemVerilog Masterclass. Software-side verification: dynamic data structures, classes, and the first UVM master keys.
The same IDE is the SystemVerilog simulator. Slang lints the file, Verilator runs it, and the waveform viewer sits next to the source.
What you will learn
Today you will learn how to use the static keyword to share a variable across all class instances and the local keyword to restrict access to instance-specific data, enabling controlled state management in verification environments.
Learning objectives
- Understand the difference between
staticandlocalclass members. - Use
staticto maintain a global counter across object instantiations. - Use
localto hide internal instance identifiers from external access. - Observe how
staticvariables retain value across object construction.
Theory
In SystemVerilog, class members can be declared static or local to control scope and lifetime.
| Keyword | Scope | Lifetime | Purpose |
|---|---|---|---|
static | Shared across all instances | Persists for entire simulation | Global counters, shared configuration |
local | Only within the class (including methods) | Instance-specific | Hidden internal state, encapsulation |
A static variable is allocated once per class, not per object, so all instances reference the same memory location. A local variable cannot be accessed outside the class—even by other instances—enforcing encapsulation.
Practice
- Open RtlStudio and select this chapter; confirm
student/rtl/design.svandstudent/tb/tb.svappear in Explore. - Open
student/tb/tb.svin the editor. - Locate the
class Itemdefinition and replace__TODO__withstaticto declare the shared counter. - Run Simulation and check the Log panel for expected output.
- (Optional) Open the Waveform tab to inspect DUT signals during stimulus.
Summary
You practiced using the static keyword to maintain a shared counter across all class instances, demonstrating global state behavior. You also used the local keyword to restrict variable visibility within the class, reinforcing encapsulation. This exercise highlighted how static members enable data sharing without requiring instance access, while local members protect internal state from unintended modification. The key takeaway is that static variables persist across object lifetimes and are shared among all instances, whereas local variables remain private to each object's scope.
Run it in the Verilog IDE
- Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
- Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
- Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
- Run Yosys when the lesson is synthesizable RTL, and keep testbench-only constructs out of that module.
The lesson is done when the simulation matches local and static members. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.