super.new
Last week I was asked a couple of questions about called base class constructors, to which I didn't know the answers. So, I did some digging. Firstly,
Can you call super.new when there is no explicit constructor in the base class?
To which the answer is: yes. I can't think why you'd want to, though.
module M;
class C;
bit b;
endclass
class P extends C;
bit b;
function new;
super.new;
endfunction
endclass
C c = new;
endmodule
https://www.edaplayground.com/x/3BB9
Can you call super.super.new?
To which the answer is: no. Section 8.15 of IEEE 1800-2107 says "There is no way to reach higher (for example, super.super.count is not allowed)."
module M;
class C;
bit b;
endclass
class P extends C;
bit b;
endclass;
class GP extends P;
bit b;
function new;
super.super.new; // this line is illegal
super.new;
endfunction
endclass;
initial begin
GP gp;
gp = new;
end
endmodule
https://www.edaplayground.com/x/3TUu
A customer asked me about this. I didn't know the answer, so I wrote a few lines of code on EDA Playground. EDA Playground is great for that, because it's always on. You don't have to queue for licences, wait for EDA tools to start, create new files, fire up editors...
Comments
Post a Comment