The local and protected access qualifiers both restrict visibility of a class's properties and methods, for the sake of encapsulation. The key difference between them: local members are not visible to subclasses at all, while protected members are visible to (and inheritable by) subclasses — both stay hidden from code outside the class hierarchy entirely.
10 min read | Intermediate Level
What You'll Learn
- What
localandprotectedboth restrict, and the one key difference between them - What happens when you try to access a
localmember from outside its class - Why
localmembers stay invisible even to child classes - Why
protectedmembers, unlikelocalones, are visible to child classes
local vs protected at a Glance
| Qualifier | Methods of the same class | Methods of a child class | Outside the class hierarchy |
|---|---|---|---|
| public (default) | Yes | Yes | Yes |
| protected | Yes | Yes | No |
| local | Yes | No | No |
Access Qualifier: local
A member declared local is available only to methods of the same class — not to child classes, and not to code outside the class at all. A method that itself accesses a local member can still be inherited and overridden by a child class, though; it's the member that stays hidden, not necessarily every method that touches it.
Accessing a local Member From Outside the Class
class ABC;
// By default, all variables are public and for this example,
// let's create two variables - one public and the other "local"
byte public_var;
local byte local_var;
// This function simply prints these variable contents
function void display();
$display ("public_var=0x%0h, local_var=0x%0h", public_var, local_var);
endfunction
endclass
module tb;
initial begin
// Create a new class object, and call display method
ABC abc = new();
abc.display();
// Public variables can be accessed via the class handle
$display ("public_var = 0x%0h", abc.public_var);
// However, local variables cannot be accessed from outside
$display ("local_var = 0x%0h", abc.local_var);
end
endmodule
Output
$display ("local_var = 0x%0h", abc.local_var);
|
ncvlog: *E,CLSNLO (testbench.sv,24|47): Access to local member 'local_var' in class 'ABC' is not allowed here.
irun: *E,VLGERR: An error occurred during parsing. Review the log file for errors with the code *E and fix those identified problems to proceed. Exiting with code (status 1).
Removing the offending line entirely, local_var is still readable from inside display(), since that method belongs to the same class:
module tb;
initial begin
ABC abc = new();
// This should be able to print local members of class ABC
// because display() is a member of ABC also
abc.display();
// Public variables can always be accessed via the class handle
$display ("public_var = 0x%0h", abc.public_var);
end
endmodule
Output
ncsim> run public_var=0x0, local_var=0x0 public_var = 0x0 ncsim: *W,RNQUIE: Simulation is complete.
Quick Check
Q: If display() were called from a completely unrelated module (not from inside ABC), would it still be able to print local_var?
Show Answer
Yes. What matters is where the method itself is defined, not where it's called from — display() is a method of ABC, so it can access ABC's local members no matter which scope actually calls abc.display().
Accessing a local Member From a Child Class
local members stay invisible even to a class that extends the one declaring them:
// Define a base class and let the variable be "local" to this class
class ABC;
local byte local_var;
endclass
// Define another class that extends ABC and have a function that tries
// to access the local variable in ABC
class DEF extends ABC;
function show();
$display ("local_var = 0x%0h", local_var);
endfunction
endclass
module tb;
initial begin
// Create a new object of the child class, and call the show method
// This will give a compile time error because child classes cannot access
// base class "local" variables and methods
DEF def = new();
def.show();
end
endmodule
Output
$display ("local_var = 0x%0h", local_var);
|
ncvlog: *E,CLSNLO (testbench.sv,10|43): Access to local member 'local_var' in class 'ABC' is not allowed here.
irun: *E,VLGERR: An error occurred during parsing. Review the log file for errors with the code *E and fix those identified problems to proceed. Exiting with code (status 1).
DEF inherits from ABC, but its own show() method still can't reach ABC's local_var — inheritance alone doesn't grant access to a base class's local members.
Access Qualifier: protected
protected is a middle ground: more restrictive than public, but less restrictive than local. A protected member is available to methods of the declaring class and to subclasses, but still not visible from outside the class hierarchy at all.
Accessing a protected Member From Outside the Class
class ABC;
// By default, all variables are public and for this example,
// let's create two variables - one public and the other "protected"
byte public_var;
protected byte protected_var;
// This function simply prints these variable contents
function void display();
$display ("public_var=0x%0h, protected_var=0x%0h", public_var, protected_var);
endfunction
endclass
module tb;
initial begin
// Create a new class object, and call display method
ABC abc = new();
abc.display();
// Public variables can be accessed via the class handle
$display ("public_var = 0x%0h", abc.public_var);
// However, protected variables cannot be accessed from outside
$display ("protected_var = 0x%0h", abc.protected_var);
end
endmodule
Output
$display ("protected_var = 0x%0h", abc.protected_var);
|
xmvlog: *E,CLSNPO (testbench.sv,29|55): Access to protected member 'protected_var' in class 'ABC' is not allowed here.
Note the different error code here (CLSNPO, versus local's CLSNLO) — the tool distinguishes exactly which access qualifier was violated.
Accessing a protected Member From a Child Class
This is the one case that behaves differently from local — a child class can reach a protected member of its parent:
// Define a base class and let the variable be "protected" to this class
class ABC;
protected byte protected_var;
endclass
// Define another class that extends ABC and have a function that tries
// to access the protected variable in ABC
class DEF extends ABC;
function show();
$display ("protected_var = 0x%0h", protected_var);
endfunction
endclass
module tb;
initial begin
// Create a new object of the child class, and call the show method
// This works fine: unlike "local", "protected" members CAN be accessed
// by methods of a child class
DEF def = new();
def.show();
end
endmodule
Output
xcelium> run protected_var = 0x0 xmsim: *W,RNQUIE: Simulation is complete.
Same structure as the failing local example earlier — but this one compiles and runs cleanly, since protected_var is exactly the kind of member protected is meant to expose to subclasses.
Quick Check
Q: If DEF in this example were instantiated and def.protected_var were accessed directly from the tb module (not through show()), would that compile?
Show Answer
No. protected only opens access to the class hierarchy itself (the declaring class and its subclasses) — tb is outside that hierarchy entirely, so a direct def.protected_var reference would fail exactly like the earlier "accessed from outside" example did.
Where Are local and protected Used?
Base classes with many subclasses — UVM's component and object base classes are a good example — commonly use protected for internal state that a derived class is expected to read or extend, while reserving local for implementation details that no subclass should ever need to touch directly, no matter how deeply it extends the hierarchy.
Common Beginner Mistakes
Mistake #1: Treating local and protected as interchangeable
Both block access from outside the class hierarchy, which can make them look equivalent at a glance. Why? The difference only shows up with subclasses — protected members are inherited and accessible in a child class, local members are not, no matter how the child class is written.
Mistake #2: Expecting a runtime warning instead of a compile error
Accessing a local or protected member from somewhere it isn't allowed fails at compile time, before simulation ever starts. Why? This is a static, structural rule about the code's scope — there's no scenario where it "usually works" and occasionally fails at run time.
Mistake #3: Assuming local means private to a single method
As the first local example shows, display() can freely read local_var even though it isn't the only method in the class. Why? local restricts visibility to the whole class, not to one specific method — any method belonging to that same class can access it.
Practice Exercise
Challenge: Mix local and protected in One Base Class
Given a base class with both a local byte secret; and a protected byte shared;, write a child class with a method that tries to access both. Which line compiles, and which doesn't?
Hint
Apply the same rule demonstrated in both sections above to each member independently — they don't have to behave the same way just because they're declared in the same class.
Solution
class Base;
local byte secret;
protected byte shared;
endclass
class Derived extends Base;
function void show();
$display ("shared = 0x%0h", shared); // Compiles fine
$display ("secret = 0x%0h", secret); // Compile error
endfunction
endclass
The line accessing shared compiles without any issue, since protected members are visible to subclasses. The line accessing secret fails to compile with the same kind of error shown earlier in this article — local members stay invisible to Derived regardless of the fact that it extends Base.
Summary
In this tutorial, you learned:
- Both
localandprotectedhide a member from code outside the class hierarchy entirely localmembers are only accessible from methods of the exact same class — not even a child class can reach themprotectedmembers are accessible from methods of the declaring class and any subclass- Both restrictions are enforced at compile time, not run time
- A method that accesses a
localorprotectedmember can still itself be inherited and overridden — it's the member's visibility that's restricted, not the method's
Continuing the Advanced Features Chapter
Continue with SystemVerilog Functions.
Class definitions can get very long once every method's full implementation sits directly between class and endclass, making it hard to see at a glance what a class actually does. The extern qualifier lets you declare a method's signature inside the class, and write its full implementation separately — the same scope resolution operator (::) used elsewhere ties the two together.
6 min read | Intermediate Level
What You'll Learn
- Why
externexists as a readability and organization tool, not just a syntax curiosity - How to declare several
externmethods so a class body reads like a table of contents - Why
virtualis never repeated in a method's external definition - What happens if an
externdeclaration and its external definition don't match exactly
Basic Syntax
The smallest possible example: declare inside the class, define outside it with ClassName::method_name:
class ABC;
// Let this function be declared here and defined later
// by "extern" qualifier
extern function void display();
endclass
// Outside the class body, we have the implementation of the
// function declared as "extern"
function void ABC::display();
$display ("Hello world");
endfunction
module tb;
// Lets simply create a class object and call the display method
initial begin
ABC abc = new();
abc.display();
end
endmodule
Output
ncsim> run Hello world ncsim: *W,RNQUIE: Simulation is complete.
Where extern Actually Earns Its Keep
A single one-line method doesn't show why this matters. The real value shows up once a class has several methods — the class body becomes a quick, scannable list of what the class can do, with every implementation detail moved out of the way:
class Counter;
local int value;
extern function new (int start_value = 0);
extern function void increment ();
extern function void decrement ();
extern function int get_value ();
endclass
function Counter::new (int start_value = 0);
value = start_value;
endfunction
function void Counter::increment ();
value++;
endfunction
function void Counter::decrement ();
value--;
endfunction
function int Counter::get_value ();
return value;
endfunction
module tb;
initial begin
Counter c = new (5);
c.increment ();
c.increment ();
c.decrement ();
$display ("value = %0d", c.get_value ());
end
endmodule
Reading just the class body — new, increment, decrement, get_value — tells you everything Counter can do in four lines, without needing to read a single line of any method's actual logic. Working through the calls by hand: new(5) sets value to 5, two calls to increment() bring it to 7, one decrement() brings it back to 6, so get_value() returns 6.
Even a constructor can be declared extern — extern function new(...); in the class body, and function Counter::new(...); ... endfunction outside it, exactly like any other method.
Quick Check
Q: Without reading any of the method bodies, how many distinct capabilities does the Counter class body tell you it has?
Show Answer
Four: a constructor (new), increment(), decrement(), and get_value(). That's the whole point of declaring them extern — the class body alone answers "what can this class do?" without needing to scroll through any implementation.
extern With virtual Methods and Different Return Types
extern works the same way regardless of whether a method is a task, returns a value, or is declared virtual — only the in-class declaration carries those qualifiers. The external definition never repeats them:
class ABC;
int data;
extern virtual function void display();
endclass
// Definition of an external function using scope
// resolution operator
function void ABC::display();
$display("data = 0x%0h", data);
endfunction
Notice the in-class declaration says extern virtual function void display();, but the external definition simply says function void ABC::display(); — no extern, no virtual. Both keywords only ever belong in the class body itself.
Where Is extern Used?
Base classes with many methods — the kind found throughout UVM, for instance — commonly declare most of their methods extern, keeping the class declaration itself short and readable as an overview, while each method's actual implementation can be organized separately, sometimes even split into a different file included alongside the class.
Common Beginner Mistakes
Mistake #1: Mismatching the declaration and the external definition
The argument list and return type in the extern declaration must match the external definition exactly. Why? A mismatch — a missing argument, a different default value, a different return type — is a compile error, since the compiler treats these as two halves of the same method signature that have to agree.
Mistake #2: Repeating extern or virtual in the external definition
As the display() example above shows, the external definition never repeats extern or virtual. Why? Both qualifiers describe how the method behaves from the class's perspective, and that's established once, in the class body — writing them again outside the class isn't valid syntax.
Mistake #3: Using extern for its own sake on trivial classes
extern's benefit is readability for classes with several substantial methods. Why? Splitting a one-line method like the first example into a declaration plus a separate definition adds indirection without actually making anything easier to read — it earns its keep once a class has enough methods that seeing them all listed together, without their bodies, is genuinely useful.
Practice Exercise
Challenge: Add a reset() Method
Extend the Counter class with a fifth extern method, reset(), that sets value back to 0.
Hint
Follow the exact same two-part pattern as the other methods: declare it extern inside the class, then define it separately using Counter::reset().
Solution
class Counter;
local int value;
extern function new (int start_value = 0);
extern function void increment ();
extern function void decrement ();
extern function int get_value ();
extern function void reset ();
endclass
// ... other method definitions unchanged ...
function void Counter::reset ();
value = 0;
endfunction
The class body now lists five capabilities instead of four, and nothing about the existing methods needed to change — the whole point of keeping declarations and implementations separate is that adding one doesn't disturb the others.
Summary
In this tutorial, you learned:
externdeclares a method's signature inside a class, with the full implementation written separately usingClassName::method_name- Its real value is readability: a class with several
externmethods reads like a table of contents, with implementation details moved out of the way - Even a constructor can be declared
extern, exactly like any other method virtualandexternonly ever appear in the in-class declaration — never repeated in the external definition- The declaration and definition must match exactly, or it's a compile error
Continuing the Advanced Features Chapter
Continue with SystemVerilog local vs protected.
A packed array refers to any dimension declared before the variable name. Unlike an Unpacked Array, a packed array is guaranteed to be represented as one contiguous set of bits — there's no gap or padding between elements.
bit [3:0] data; // Packed array or vector
logic queue [9:0]; // Unpacked array
Because a packed array must map onto a contiguous bit vector, it can only be built from the single-bit data types (bit, logic, reg), enumerated types, and — recursively — other packed arrays and packed structs. You can't pack an int, a string, or a class handle.
7 min read | Intermediate Level
What You'll Learn
- What makes a packed array different from an unpacked array
- Declare and index a single-dimensional packed array (vector)
- Work with multidimensional packed arrays and understand segment slicing
- Know which dimension varies fastest inside a packed array
Syntax
A packed dimension is any [msb:lsb] that appears before the variable name.
data_type [msb:lsb] array_name; // single-dimensional packed (vector)
data_type [msb1:lsb1] [msb2:lsb2] array_name; // multidimensional packed array
data_type– must be a single-bit type (bit,logic,reg), anenumtype, or another packed array/structarray_name– the identifier for the array[msb:lsb]– each pair of brackets before the name adds one more packed dimension
A dimension written before the name (e.g. bit [7:0] data;) is packed — the bits are stored contiguously as a single vector. A dimension written after the name (e.g. bit data [7:0];) is unpacked — it creates 8 separate elements instead. Mixing these up changes the meaning of the variable entirely.
Single Dimensional Packed Arrays
A one-dimensional packed array is also called a vector. Since [7:0] is written before m_data, every bracket is a packed dimension, and m_data[i] selects a single bit.
module tb;
bit [7:0] m_data; // A vector or 1D packed array
initial begin
// 1. Assign a value to the vector
m_data = 8'hA2;
// 2. Iterate through each bit of the vector and print value
for (int i = 0; i < $size(m_data); i++) begin
$display ("m_data[%0d] = %b", i, m_data[i]);
end
end
endmodule
Output
ncsim> run m_data[0] = 0 m_data[1] = 1 m_data[2] = 0 m_data[3] = 0 m_data[4] = 0 m_data[5] = 1 m_data[6] = 0 m_data[7] = 1 ncsim: *W,RNQUIE: Simulation is complete.
$size(m_data) returns 8 here — the number of bits in the packed vector — and each m_data[i] access returns exactly one bit, not a byte or a sub-word.
Packed vectors are the everyday building block for RTL: bus widths, register fields, ALU operands, and address/data signals are almost always modeled as packed bit or logic vectors so they map cleanly onto real hardware wires.
Quick Check
Q: For bit [7:0] m_data;, what does m_data[3] return — a single bit or a byte?
Show Answer
A single bit (bit position 3). This is a 1D packed vector, so every index selects one bit of the 8-bit contiguous vector, not a byte-sized chunk.
Multidimensional Packed Arrays
A multidimensional packed array is still one contiguous set of bits, but the declaration segments it into smaller, individually addressable groups.
Example #1
The code below declares a 2D packed array that occupies 32 bits (4 bytes) and walks through each byte-sized segment.
module tb;
bit [3:0][7:0] m_data; // A MDA, 4 bytes
initial begin
// 1. Assign a value to the MDA
m_data = 32'hface_cafe;
$display ("m_data = 0x%0h", m_data);
// 2. Iterate through each segment of the MDA and print value
for (int i = 0; i < $size(m_data); i++) begin
$display ("m_data[%0d] = %b (0x%0h)", i, m_data[i], m_data[i]);
end
end
endmodule
Output
ncsim> run m_data = 0xfacecafe m_data[0] = 11111110 (0xfe) m_data[1] = 11001010 (0xca) m_data[2] = 11001110 (0xce) m_data[3] = 11111010 (0xfa) ncsim: *W,RNQUIE: Simulation is complete.
Here, [3:0] is the outer packed dimension and [7:0] is the inner one, written right next to the name. Since [7:0] is closer to m_data, indexing with m_data[i] now returns a full byte (the [7:0] segment) instead of a single bit like in the vector example.
Example #2
A 3D packed array works the same way, just with one more level of segmentation.
module tb;
bit [2:0][3:0][7:0] m_data; // An MDA, 12 bytes
initial begin
// 1. Assign a value to the MDA
m_data[0] = 32'hface_cafe;
m_data[1] = 32'h1234_5678;
m_data[2] = 32'hc0de_fade;
// m_data gets a packed value
$display ("m_data = 0x%0h", m_data);
// 2. Iterate through each segment of the MDA and print value
foreach (m_data[i]) begin
$display ("m_data[%0d] = 0x%0h", i, m_data[i]);
foreach (m_data[i][j]) begin
$display ("m_data[%0d][%0d] = 0x%0h", i, j, m_data[i][j]);
end
end
end
endmodule
Output
ncsim> run m_data = 0xc0defade12345678facecafe m_data[2] = 0xc0defade m_data[2][3] = 0xc0 m_data[2][2] = 0xde m_data[2][1] = 0xfa m_data[2][0] = 0xde m_data[1] = 0x12345678 m_data[1][3] = 0x12 m_data[1][2] = 0x34 m_data[1][1] = 0x56 m_data[1][0] = 0x78 m_data[0] = 0xfacecafe m_data[0][3] = 0xfa m_data[0][2] = 0xce m_data[0][1] = 0xca m_data[0][0] = 0xfe ncsim: *W,RNQUIE: Simulation is complete.
m_data here is bit [2:0][3:0][7:0] — three packed dimensions totaling 3 × 4 × 8 = 96 bits. m_data[2] selects the outermost segment (a 32-bit chunk), and m_data[2][3] narrows further into a single byte within it. Reading left to right, m_data[2] is the most-significant 32 bits and m_data[0] is the least-significant, which is why the full value prints as m_data[2] concatenated with m_data[1] concatenated with m_data[0].
This is the same rule that governs any packed declaration: the dimension written closest to the variable name varies fastest, and the one written farthest away (the outermost, leftmost bracket) varies slowest. In bit [2:0][3:0][7:0] m_data, that means [7:0] (individual bits) changes fastest, [3:0] (bytes within a segment) changes next, and [2:0] (the outer segment) changes slowest.
This same "closest to the name varies fastest" rule also applies to unpacked arrays, though for unpacked dimensions it works in the opposite direction — the dimension farthest from the name is the fastest-varying one there.
Quick Check
Q: In bit [2:0][3:0][7:0] m_data;, which named dimension changes faster as you walk through the array — [3:0] or [2:0]?
Show Answer
[3:0] changes faster. It's written closer to the variable name than [2:0], so per the packed-dimension rule, it varies faster. [2:0], being the outermost/leftmost dimension, varies slowest of the three.
Multidimensional packed arrays show up naturally when modeling things like a register file made of fixed-width words, a memory model where each entry is further split into byte lanes, or bus data that needs both word-level and byte-level access in the same variable.
What It Synthesizes Into
A multidimensional packed array is still one contiguous vector, so the extra dimension only changes how you index it. The register below stores four bytes as logic [3:0][7:0] and lets each byte be written on its own.
module byte_reg (
input logic clk, we,
input logic [3:0] be,
input logic [3:0][7:0] wdata,
output logic [3:0][7:0] q
);
always_ff @(posedge clk)
if (we)
for (int i = 0; i < 4; i++)
if (be[i]) q[i] <= wdata[i];
endmodule
Synthesis result: With the default synthesis flow of ChipVerify Lab (Yosys with the SkyWater 130 nm high-density cell library), this module builds 32 flip-flops with a built-in enable and 4 AND gates, one per byte, that combine we with that byte's be bit. The same register written as a flat logic [31:0] with q[i*8 +: 8] slices builds exactly the same 36 cells. Indexing q[i] selects bits i*8+7 down to i*8, which is only wiring.
Common Mistakes
Mistake #1: Trying to pack a multi-bit or non-bit type
Wrong: int [3:0] data; or string [3:0] data;
Right: bit [3:0][31:0] data; using bit as the base type
Why? A packed array must resolve to a contiguous bit vector, so every level has to bottom out in a single-bit type like bit or logic (enum types and packed structs are allowed too, since they ultimately resolve to bit/logic) — types like int, string, or class handles can't be packed.
Mistake #2: Assuming array[i] always returns a single bit
For a plain vector like bit [7:0] m_data;, m_data[i] returns one bit. But for a multidimensional packed array like bit [3:0][7:0] m_data;, m_data[i] returns the entire inner segment (a full byte here), not a single bit. Always check how many packed dimensions are declared before assuming what an index returns.
Mistake #3: Treating a packed array as resizable
Just like a fixed-size unpacked array, the size of every packed dimension is fixed at compile time. If the number of bits needs to change at runtime, packed arrays are not the right tool — that's a job for a dynamic array built from packed elements.
Mistake #4: Misreading which end is the MSB
In bit [3:0] data;, the leftmost number in [msb:lsb] is the most-significant bit, so data[3] is the MSB and data[0] is the LSB. Writing the range backwards, like [0:3], is legal SystemVerilog but flips this convention and is a common source of off-by-one bugs when connecting to other signals.
Practice Exercise
Challenge: Model a 2-Channel Data Bus
Declare a packed array named channel_data that represents 2 channels, each 8 bits wide, using a single packed variable. Assign it a 16-bit value, print each channel with %b and %0h, and print just bit 3 of channel 0.
Hint
You need two packed dimensions: an outer one for the channel index and an inner one for the 8 bits of each channel, e.g. bit [1:0][7:0] channel_data;.
Solution
module tb;
bit [1:0][7:0] channel_data; // 2 channels, 8 bits each
initial begin
channel_data = 16'hA53C;
for (int i = 0; i < $size(channel_data); i++) begin
$display("channel_data[%0d] = %b (0x%0h)", i, channel_data[i], channel_data[i]);
end
$display("channel_data[0] bit 3 = %b", channel_data[0][3]);
end
endmodule
Summary
In this tutorial, you learned:
- A packed dimension is any
[msb:lsb]declared before the variable name, and it's guaranteed to be a contiguous set of bits - A single-dimensional packed array (a vector) indexes down to a single bit
- A multidimensional packed array segments the same contiguous bits into smaller addressable groups, like bytes within a word
- The packed dimension closest to the variable name varies fastest, while the outermost one varies slowest
- Packed arrays can only be built from single-bit types (
bit,logic,reg), enum types, and other packed arrays/structs, and their size is fixed at compile time
Concurrent assertions describe behavior that spans over simulation time and are evaluated only at the occurrence of a clock tick.
SystemVerilog concurrent assertion statements can be specified in a module, interface, or program block, running concurrently with other statements. Here are the properties of a concurrent assertion:
- The test expression is evaluated at clock edges, based on values in sampled variables
- Sampling of variables happens in the preponed region, and evaluation of the expression happens in the observed region of the simulation scheduler
- It can be placed in a procedural, module, interface, or program block
- It can be used in both dynamic (simulation) and formal verification techniques
10 min read | Intermediate Level
What You'll Learn
- The defining properties of a concurrent assertion: when it's evaluated, and where it can be used
- Why the preponed region determines exactly which value of a signal gets checked on a given clock edge
- How changing just the boolean expression inside the same
assert propertyproduces completely different pass/fail behavior - How to read the "Offending" annotation in a failed assertion's log output
Example #1: AND
Two signals a and b are driven at positive clock edges with random values. The assertion checks that both signals are expected to be high at every positive edge of the clock for the entire simulation — it should fail for every instance where either a or b is found to be zero:
module tb;
bit a, b;
bit clk;
always #10 clk = ~clk;
initial begin
for (int i = 0; i < 10; i++) begin
@(posedge clk);
a <= $random;
b <= $random;
$display("[%0t] a=%0b b=%0b", $time, a, b);
end
#10 $finish;
end
// This assertion runs for entire duration of simulation
// Ensure that both signals are high at posedge clk
assert property (@(posedge clk) a & b);
endmodule
The assertion is executed on every positive edge of clk and evaluates the expression using values of the variables in the preponed region — a delta cycle before the given clock edge. So if a changes from 0 to 1 on the same edge that clk goes from 0 to 1, the value of a taken for the assertion is still zero, because that's what it was just before the clock edge.

Assertion fails for all cases where either a or b is found zero, since the expression is expected to be true for the entire duration of the simulation:
| Time (ns) | a | b | Result |
|---|---|---|---|
| 10 | 0 | 0 | FAIL |
| 30 | 0 | 1 | FAIL |
| 50 | 1 | 1 | PASS |
| 70 | 1 | 1 | PASS |
| 90 | 1 | 0 | FAIL |
| 110 | 1 | 1 | PASS |
| 130 | 0 | 1 | FAIL |
| 150 | 1 | 0 | FAIL |
| 170 | 1 | 0 | FAIL |
| 190 | 1 | 0 | FAIL |
Output
Compiler version P-2019.06-1; Runtime version P-2019.06-1; Dec 11 14:46 2019 [10] a=0 b=0 testbench.sv", 24: tb.unnamed$$_4: started at 10ns failed at 10ns Offending '(a & b)' [30] a=0 b=1 "testbench.sv", 24: tb.unnamed$$_4: started at 30ns failed at 30ns Offending '(a & b)' [50] a=1 b=1 [70] a=1 b=1 [90] a=1 b=0 "testbench.sv", 24: tb.unnamed$$_4: started at 90ns failed at 90ns Offending '(a & b)' [110] a=1 b=1 [130] a=0 b=1 "testbench.sv", 24: tb.unnamed$$_4: started at 130ns failed at 130ns Offending '(a & b)' [150] a=1 b=0 "testbench.sv", 24: tb.unnamed$$_4: started at 150ns failed at 150ns Offending '(a & b)' [170] a=1 b=0 "testbench.sv", 24: tb.unnamed$$_4: started at 170ns failed at 170ns Offending '(a & b)' [190] a=1 b=0 "testbench.sv", 24: tb.unnamed$$_4: started at 190ns failed at 190ns Offending '(a & b)' $finish called from file "testbench.sv", line 14. $finish at simulation time 200
Quick Check
Q: Suppose a was driven with a plain blocking assignment instead of <=, and happened to change from 0 to 1 in the exact same delta cycle as a clock edge. Would the assertion see the new value (1) or the old value (0)?
Show Answer
The old value (0). Assertions sample in the preponed region, which captures values as they stood just before the clock edge — regardless of exactly how or when a value changes elsewhere in that same time step, the assertion only ever sees what was true immediately prior to the edge it's evaluating on.
Example #2: OR
The same testbench, but the property now checks that at least one of the two signals is high on every clock instead of requiring both:
module tb;
bit a, b;
bit clk;
always #10 clk = ~clk;
initial begin
for (int i = 0; i < 10; i++) begin
@(posedge clk);
a <= $random;
b <= $random;
$display("[%0t] a=%0b b=%0b", $time, a, b);
end
#10 $finish;
end
// This assertion runs for entire duration of simulation
// Ensure that atleast 1 of the two signals is high on every clk
assert property (@(posedge clk) a | b);
endmodule

| Time (ns) | a | b | Result |
|---|---|---|---|
| 10 | 0 | 0 | FAIL |
| 30 | 0 | 1 | PASS |
| 50 | 1 | 1 | PASS |
| 70 | 1 | 1 | PASS |
| 90 | 1 | 0 | PASS |
| 110 | 1 | 1 | PASS |
| 130 | 0 | 1 | PASS |
| 150 | 1 | 0 | PASS |
| 170 | 1 | 0 | PASS |
| 190 | 1 | 0 | PASS |
Output
Compiler version P-2019.06-1; Runtime version P-2019.06-1; Dec 11 15:13 2019 [10] a=0 b=0 testbench.sv", 24: tb.unnamed$$_4: started at 10ns failed at 10ns Offending '(a | b)' [30] a=0 b=1 [50] a=1 b=1 [70] a=1 b=1 [90] a=1 b=0 [110] a=1 b=1 [130] a=0 b=1 [150] a=1 b=0 [170] a=1 b=0 [190] a=1 b=0 $finish called from file "testbench.sv", line 14.
Only the very first cycle (10ns, where both are 0) fails — the exact same random stimulus as Example #1, but a dramatically different pass/fail pattern, purely from swapping & for | in the property itself.
Quick Check
Q: Using the identical stimulus, at 90ns (a=1, b=0), Example #1's AND property failed. Why does Example #2's OR property pass at that same moment?
Show Answer
Because a | b only needs one of the two to be true, and a is 1 — that alone satisfies the OR condition, even though b is 0. The AND property required both to be true, which b=0 violates.
Example #3: XOR (Written as a Negated XNOR)
The property expression is modified once more, this time to !(!a ^ b):
module tb;
bit a, b;
bit clk;
always #10 clk = ~clk;
initial begin
for (int i = 0; i < 10; i++) begin
@(posedge clk);
a <= $random;
b <= $random;
$display("[%0t] a=%0b b=%0b", $time, a, b);
end
#10 $finish;
end
// This assertion runs for entire duration of simulation
// Ensure that atleast 1 of the two signals is high on every clk
assert property (@(posedge clk) !(!a ^ b));
endmodule

| Time (ns) | a | b | Expression !(!a ^ b) | Result |
|---|---|---|---|---|
| 10 | 0 | 0 | 0 | FAIL |
| 30 | 0 | 1 | 1 | PASS |
| 50 | 1 | 1 | 0 | FAIL |
| 70 | 1 | 1 | 0 | FAIL |
| 90 | 1 | 0 | 1 | PASS |
| 110 | 1 | 1 | 0 | FAIL |
| 130 | 0 | 1 | 1 | PASS |
| 150 | 1 | 0 | 1 | PASS |
| 170 | 1 | 0 | 1 | PASS |
| 190 | 1 | 0 | 1 | PASS |
Output
Compiler version P-2019.06-1; Runtime version P-2019.06-1; Dec 11 15:26 2019 [10] a=0 b=0 "testbench.sv", 24: tb.unnamed$$_4: started at 10ns failed at 10ns Offending '(!((!a) ^ b))' [30] a=0 b=1 [50] a=1 b=1 "testbench.sv", 24: tb.unnamed$$_4: started at 50ns failed at 50ns Offending '(!((!a) ^ b))' [70] a=1 b=1 "testbench.sv", 24: tb.unnamed$$_4: started at 70ns failed at 70ns Offending '(!((!a) ^ b))' [90] a=1 b=0 [110] a=1 b=1 "testbench.sv", 24: tb.unnamed$$_4: started at 110ns failed at 110ns Offending '(!((!a) ^ b))' [130] a=0 b=1 [150] a=1 b=0 [170] a=1 b=0 [190] a=1 b=0 $finish called from file "testbench.sv", line 14. $finish at simulation time 200
Working through the boolean algebra, !(!a ^ b) simplifies to exactly a != b — in other words, this convoluted-looking expression is just an XOR(a, b) check written a longer way. Checking every row of the table above confirms it: the property passes precisely on the cycles where a and b differ, and fails on every cycle where they match.
Quick Check
Q: Given that !(!a ^ b) is equivalent to a != b, what single, simpler operator could replace the entire expression?
Show Answer
a ^ b (plain XOR) — ^ is already true exactly when its two operands differ, which is exactly what the longer, double-negated expression computes.
Where Are Simple Boolean Concurrent Assertions Used?
Lightweight, single-cycle boolean checks like these are a common sanity-check layer sitting alongside more complex protocol-sequence assertions — checking things like "request and acknowledge should never differ for more than a cycle" or "these two mutually-exclusive control signals should never both be high at once," every single clock, for the entire run.
Common Beginner Mistakes
Mistake #1: Assuming a concurrent assertion samples the current (post-edge) value
As Example #1 explains, sampling happens in the preponed region — the value as it stood just before the clock edge. Why? A signal that changes in the same delta cycle as the clock edge won't be seen as changed by the assertion on that specific edge; it'll be picked up on the next one instead.
Mistake #2: Forgetting concurrent assertions work for formal verification too
Unlike immediate assertions, which are simulation-only, concurrent assertions can be used in both dynamic (simulation) and formal verification. Why? This is exactly why concurrent assertions are the foundation formal tools build on — their clock-based, declarative structure translates directly into something a formal solver can reason about.
Mistake #3: Writing an unnecessarily complex boolean expression
As the third example shows, !(!a ^ b) and a ^ b are functionally identical, but one is far easier to read at a glance. Why? A property that's hard to read is harder to trust during a code review — simplifying an expression algebraically before writing it into an assertion is worth the extra minute.
Mistake #4: Assuming "Offending" always names one specific signal
In these examples, the "Offending" annotation names the entire boolean expression, since that's the whole of what's being checked. Why? For more complex, multi-part sequences (covered in SystemVerilog Assertions and the articles that follow), the same annotation instead names whichever specific piece of the sequence actually broke — it's worth reading carefully rather than assuming it always means the same thing.
Practice Exercise
Challenge: Predict a NAND Property
Using the exact same stimulus sequence from Example #1 (10ns: a=0,b=0; 30ns: a=0,b=1; 50ns: a=1,b=1; 90ns: a=1,b=0), predict the pass/fail result at each of those four times for the property assert property (@(posedge clk) !(a & b)); (NAND).
Hint
!(a & b) is true whenever a and b are not both 1 — it only fails when both are simultaneously high.
Solution
10ns (0,0): PASS — not both high. 30ns (0,1): PASS — not both high. 50ns (1,1): FAIL — both are high, which is the one case NAND forbids. 90ns (1,0): PASS — not both high. NAND is the exact opposite of the AND property from Example #1 — it fails only where AND would have passed.
Summary
In this tutorial, you learned:
- A concurrent assertion is evaluated at every occurrence of a clock edge, using values sampled in the preponed region — just before that edge
- Concurrent assertions can be used in modules, interfaces, or programs, and work for both simulation and formal verification
- Swapping the boolean operator inside an otherwise identical
assert propertycan completely change which cycles pass or fail against the same stimulus - A complex-looking boolean expression can often be simplified algebraically —
!(!a ^ b)is justa != bin disguise - The "Offending" annotation in a failure log names whatever specific part of the checked expression actually caused the failure
::, is how SystemVerilog lets you say precisely which one you mean, instead of leaving it to guesswork or accidental shadowing.The scope resolution operator :: is used to refer to an identifier within the scope of a class, package, covergroup, coverpoint, cross, or typedef name. The left-hand side must be one of those scope names; the right-hand side is an identifier inside that scope, like a variable or method name.
7 min read | Intermediate Level
What You'll Learn
- What
::does, and what's legal on each side of it - How to define a class method's body outside the class declaration itself
- How
::accesses a class's static members without needing an object - How to reference a package's members directly, with or without importing the package
- How
::resolves a naming collision between an imported package and a local declaration
Why Is the Scope Resolution Operator Required?
Classes and other scopes can have identically-named identifiers, which can create a namespace collision if referred to without specifying which scope you mean. :: uniquely identifies a member or parameter of a given scope. It's also used to access a class's static variables and methods, parameters, and local parameters from outside the class, and to access public and protected members of a base class from within a derived class.
Defining an extern Function
A method can be declared inside a class with extern, and its actual body defined separately, outside the class, using :: to say which class it belongs to:
class ABC;
int data;
extern virtual function void display();
endclass
// Definition of an external function using scope
// resolution operator
function void ABC::display();
$display("data = 0x%0h", data);
endfunction
module tb;
initial begin
ABC abc = new();
abc.data = 32'hface_cafe;
abc.display();
end
endmodule
Output
ncsim> run data = 0xfacecafe ncsim: *W,RNQUIE: Simulation is complete. ncsim> exit
ABC::display() is what tells the compiler "this function body belongs to the display() method declared inside ABC," even though it's written outside the class entirely.
Quick Check
Q: What would happen if function void ABC::display();...endfunction were never written anywhere in the code?
Show Answer
A compile error. extern only declares that the method exists and what its signature looks like — the actual body still has to be provided somewhere, using :: to tie it back to the class.
Accessing Static Methods and Variables
A class's static members belong to the class itself, not to any one object, and :: lets you reach them without creating an instance first:
class ABC;
static int data;
static function void display();
$display("data = 0x%0h", data);
endfunction
endclass
module tb;
initial begin
ABC a1, a2;
// Assign to static variable before creating
// class objects, and display using class_type and
// scope resolution operator
ABC::data = 32'hface_cafe;
ABC::display();
a1 = new();
a2 = new();
$display ("a1.data=0x%0h a2.data=0x%0h", a1.data, a2.data);
end
endmodule
Output
ncsim> run data = 0xfacecafe a1.data=0xfacecafe a2.data=0xfacecafe ncsim: *W,RNQUIE: Simulation is complete. ncsim> exit
ABC::data is assigned before either a1 or a2 even exists, and both objects still see the same value once created — exactly what static means: one shared copy for the whole class, not one per object. See SystemVerilog Static Variables & Functions for more on this.
Quick Check
Q: If a third object, a3 = new(), were created right after this code, and then a1.data were changed to a new value, what would a3.data show?
Show Answer
The new value. Since data is static, a1.data, a2.data, and a3.data are all just different names for the exact same underlying storage — changing it through any one of them changes what all of them see.
Referencing Package Members
:: can also reach directly into a package, referencing a type or parameter declared there without importing the whole package first — the package just needs to be included in compilation:
package my_pkg;
typedef enum bit {FALSE, TRUE} e_bool;
endpackage
module tb;
bit val;
initial begin
// Refer to types that have been declared
// in a package. Note that package has to
// be included in compilation but not
// necessarily "imported"
val = my_pkg::TRUE;
$display("val = 0x%0h", val);
end
endmodule
Output
ncsim> run val = 0x1 ncsim: *W,RNQUIE: Simulation is complete. ncsim> exit
my_pkg::TRUE reaches directly into the package to grab its TRUE enum value (1, since it's the second value declared in FALSE, TRUE) without an import statement anywhere.
Avoiding Namespace Collisions
Things get more interesting when a locally-declared identifier shares a name with something already imported from a package:
package my_pkg;
typedef enum bit {FALSE, TRUE} e_bool;
endpackage
import my_pkg::*;
module tb;
typedef enum bit {TRUE, FALSE} e_bool;
initial begin
e_bool val;
// Be explicit and say that TRUE from my_pkg
// should be assigned to val
val = my_pkg::TRUE;
$display("val = 0x%0h", val);
// TRUE from current scope will be assigned to
// val
val = TRUE;
$display("val = 0x%0h", val);
end
endmodule
Output
ncsim> run val = 0x1 val = 0x0 ncsim: *W,RNQUIE: Simulation is complete. ncsim> exit
Notice the local e_bool reverses the order: TRUE, FALSE instead of the package's FALSE, TRUE — so the module's own TRUE is 0, while the package's TRUE is 1. val = my_pkg::TRUE explicitly forces the package's version, giving 0x1. val = TRUE, with no qualification, resolves to the module's own local declaration instead — giving 0x0 — because a local declaration takes precedence over a wildcard-imported (import my_pkg::*;) one, even though both are visible in the same scope.
Quick Check
Q: If the module's local typedef were removed entirely, what would val = TRUE; (unqualified) resolve to?
Show Answer
The package's TRUE (value 1). With no local declaration to shadow it, the wildcard-imported my_pkg::* version becomes the only TRUE visible in that scope, so the unqualified reference resolves to it.
Where Does This Matter in Practice?
Large verification environments commonly share types, parameters, and enums across many files through packages, often pulled in with a wildcard import for convenience. Relying on that convenience everywhere means a locally-declared identifier with the same name can silently shadow the package's version with no warning — explicit :: qualification is the way to be certain which one is actually being used when it matters.
Common Beginner Mistakes
Mistake #1: Assuming a wildcard import behaves exactly like a local declaration
As the namespace collision example shows, a local declaration silently wins over a wildcard-imported identifier with the same name. Why? This can produce a value that looks wrong at first glance if you forgot a local declaration existed and expected the package's version to be used instead — explicit :: removes the ambiguity entirely.
Mistake #2: Forgetting to actually define an extern-declared method
extern only declares a method's signature inside the class — it doesn't provide a body. Why? If ClassName::method_name(...) is never written anywhere, the method has no implementation, and you'll get a compile error rather than a working (if empty) function.
Mistake #3: Thinking :: is only for static members
:: shows up in several different contexts — defining an extern method's body, accessing static members, reaching into a package, and accessing base-class members from a derived class. Why? Treating it as purely a "static member" operator misses how often it's actually used just to disambiguate which scope an identifier belongs to.
Practice Exercise
Challenge: Trace a Different Collision
Given package p; typedef enum bit [1:0] {RED, GREEN, BLUE, YELLOW} e_color; endpackage, imported with import p::*;, and a module that locally declares typedef enum bit [1:0] {YELLOW, BLUE, GREEN, RED} e_color;, what would e_color c; c = RED; (unqualified) evaluate to, and what would c = p::RED; evaluate to?
Hint
Work out each enum's ordinal values separately first — the package's declaration order, and the module's local declaration order — then apply the same shadowing rule from the article.
Solution
c = RED; gives 3, using the local declaration (YELLOW=0, BLUE=1, GREEN=2, RED=3), since the local typedef shadows the wildcard import. c = p::RED; gives 0, explicitly forcing the package's own ordering (RED=0, GREEN=1, BLUE=2, YELLOW=3) regardless of what's declared locally.
Summary
In this tutorial, you learned:
::resolves an identifier to a specific scope — a class, package, covergroup, coverpoint, cross, or typedef name on its left-hand side- An
extern-declared method's body is defined outside the class usingClassName::method_name - A class's
staticmembers are accessed withClassName::member_name, without needing an object instance - A package's members can be referenced directly with
package_name::member_name, even without importing the package - A local declaration silently shadows a same-named identifier pulled in through a wildcard
import— explicit::qualification removes that ambiguity
Continuing the Advanced Features Chapter
Continue with SystemVerilog 'extern' for a deeper look at declaring methods outside a class body.
Quiz
No quiz questions available for this article.