Daniel is asking whether initialization of static class properties takes place when objects if that particular class are not created.
The LRM does not specify whether the initialization of such properties can be optimized away. But, like for other optimizations, the LRM should not define such behavior. Instead, implementations should be able to apply these optimizations so long as they do not change the behavior. In Daniel's example, the side-effect should be enough to prevent such an optimization.
Additionally, the optimization would also need to check that the static properties are not referenced from without via the scope resolution operator, (p::A::I or A::I in the examples). And then the situation is exactly the same as with any other static (module level) variable and is not unique to classes.
Arturo
From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of Francoise Martinolle
Sent: Wednesday, February 17, 2010 10:18 AM
To: Daniel Mlynek; sv-ec@eda.org
Subject: RE: [sv-ec] static members initialization in class nested in package
Daniel,
I believe it should display the hello msg but I cannot find text in the LRM saying this.
The only relevant text I found is in section 8.8
In section 8.8, there is an example f a static property opening a file. After the example it says that the property fileId should
be created an initialized. This class is a parameterless class, so it only has one specialization.
It is unclear what happen to default class specializations of parameterized classes.
Francoise
'
________________________________
From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of Daniel Mlynek
Sent: Wednesday, February 17, 2010 9:35 AM
To: sv-ec@eda.org
Subject: [sv-ec] static members initialization in class nested in package
In below code there is class A nested in package. Class A is never used, but it has static member which is initialized with function call. This function has side efect - it this example it displays a string on console.
How it should work? I cannot figure it out form LRM. Is it somewhere explicitly said in LRM?
CODE:
package p;
class A;
static function int f;
$display("hello p"); //should it be displayed?
return 0;
endfunction
static int i = f();
endclass
endpackage
module top;
import p::*;
initial
$display("hello");
endmodule
Similar problem for version with no packages:
class A;
static function int f;
$display("hello p"); //should it be displayed?
return 0;
endfunction
static int i = f();
endclass
module top;
initial
$display("hello");
endmodule
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<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 Wed Feb 17 11:27:30 2010
This archive was generated by hypermail 2.1.8 : Wed Feb 17 2010 - 11:27:33 PST