An extern method provides a facility for class methods to define them outside of the class body.

If the method definition is lengthy (many lines of code inside a method), the extern method provides better readability and cleaner implementation of the class.

An extern keyword is used for method declaration and a class name with a scope resolution operator is used for method definition.

  1. Method definition and declaration should have the same number of argument lists, data types, and argument names.
  2. For the extern function return type should be the same if used.

Extern method example

The following example has both extern function and extern task implemented.

class transaction;
  bit [31:0] data;
  int id;

  extern function void display();
  extern task delay();

function void transaction::display();
  $display("data = %0d and id = %0d", data, id);
task transaction::delay();
  $display("Time = %0.0t, delayed data = %0d", $time, data);

module class_example;
  transaction tr;
  initial begin
    tr = new(); = 100; = 1;


data = 100 and id = 1
Time = 50, delayed data = 100

System Verilog Tutorials