Extern method in Classes
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.
- Method definition and declaration should have the same number of argument lists, data types, and argument names.
- 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();
endclass
function void transaction::display();
$display("data = %0d and id = %0d", data, id);
endfunction
task transaction::delay();
#50;
$display("Time = %0.0t, delayed data = %0d", $time, data);
endtask
module class_example;
transaction tr;
initial begin
tr = new();
tr.data = 100;
tr.id = 1;
tr.display();
tr.delay();
end
endmodule
Output:
data = 100 and id = 1
Time = 50, delayed data = 100
System Verilog Tutorials