Shalom, > The Doulos SV Golden Reference Guide says the following, > "If the new() function of a subclass is overridden, it does not call > the parent class's constructor by default. This will almost always > need to be called explicitly as the first statement in the > overloaded constructor." > Is this correct? It is certainly not clear from the LRM. If this is the case, it is at best misleading and at worst wrong, and we (Doulos) need to fix it. First off, I'm not sure "override" is the right term to use for a user-written constructor in a derived class. I was under the impression that "override" strictly applies only to virtual methods. Second, there is no doubt that SV implicitly calls super.new(), with no argument, unless the first executable statement of a derived class's constructor is an explicit call to super.new(). We take some care to explain how a defaulted call to super.new() will go wrong if super.new has one or more mandatory arguments, and that's probably where the misleading text springs from. For my part, I'll take an action to get that cleaned-up in our GRG. However, the SV LRM could perhaps be a little more helpful than it is in clarifying this behaviour. There are some corner cases that don't seem to me to be too clear. In particular, any attempt to compute the arguments to super.new() will seriously muddy the waters: class C; function new(int x); ... endclass : C class D extends C; function new(bit b); if (b) super.new(-1); else super.new(1); ... Is that legal? If not, could it be made legal thus? function D::new(bit b); super.new(b? -1: 1); Would it be legal to call a function to compute the arguments? (Evidently, not a *member* function.) In all such cases, super.new() is not the first executable code in D::new() even if it is lexically the first code to appear. Thanks -- Jonathan Bromley Consultant DOULOS - Developing Design Know-how VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK Tel: +44 (0)1425 471223 Email: jonathan.bromley@doulos.com Fax: +44 (0)1425 471573 Web: http://www.doulos.com This message may contain personal views which are not the views of Doulos Ltd., unless specifically stated. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Thu Feb 12 06:29:21 2009
This archive was generated by hypermail 2.1.8 : Thu Feb 12 2009 - 06:29:59 PST