Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

When Class Constructor Is Implicitly Called

SystemVerilog Classes & OOP

A class with no new(): the tool supplies a default constructor, so the member simply keeps its default value of 0.

Open in IDE
testbench.sv
// Define a simple class with a variable called "addr"
// Note that the new() function is not defined here
class Packet;
	bit [31:0] addr;
endclass

module tb;
  
  	// When the class object is instantiated, then the constructor is
  	// implicitly defined by the tool and called
	initial begin
		Packet pkt = new;   
		$display ("addr=0x%0h", pkt.addr);
	end
endmodule

/* 
Simulation Log:
---------------
ncsim> run
addr=0x0
ncsim: *W,RNQUIE: Simulation is complete.
ncsim> exit
*/
design.sv
// Code your design here
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.