Daniel, The semantics of such initializers are discussed in page 85 of 2005 LRM (see second sentence below): The new operation is defined as a function with no return type, and like any other function, it must be non-blocking. Even though new does not specify a return type, the left-hand side of the assignment determines the return type. Class properties that include an initializer in their declaration are initialized before the execution of the user-defined class constructor. Thus, initializer values can be overridden by the class constructor. I believe using "this" in the declaration is illegal - "this" is only visible within non-static methods. Otherwise, your example: class A ; int i = 5; int j = i; A a = this; endclass is equivalent (and correct) to: class A ; int i; int j; A a; function new(); i = 5; j = i; a = this; // this seems weird, but valid nonetheless endfunction endclass Arturo ________________________________ From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of danielm Sent: Friday, January 18, 2008 7:00 AM To: sv-ec@eda.org Subject: [sv-ec] initializing class properties I haven't found an explicit LRM saying if class properties can be initialized but LRM uses examples like: class A ; integer j = 5; endclass Is it allowed somwhere in LRM or this is just a mistake? IMHO allowing such code is problematic. Other mature languages like ie C++ do not allowed such initialization. In fact 'j' is dynamic doesn't exist at the moment when it is initialized - because of that the contructor is proper place for variable initializations. 'j is created when object is created by constructor. Initialization is a reason why the constructor was introduced into the language. Allowing class properties to be initialized iallows not only such simple examples as above but also more complicated cases where we initialize non existing variable with other non existing varialbe: class A ; int i = 5; int j = i; A a = this; endclass All above is not neat coding sample - why LRM does not explicitly forbids such codes. DANiel -- This message has been scanned for viruses and dangerous content by MailScanner <http://www.mailscanner.info/> , and is believed to be clean. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Fri Jan 18 15:08:01 2008
This archive was generated by hypermail 2.1.8 : Fri Jan 18 2008 - 15:08:26 PST