[sv-ec] member initialization at declaration vs. constructor - order issue

From: Daniel Mlynek <daniel.mlynek_at_.....>
Date: Thu Aug 28 2008 - 08:09:14 PDT
I've hit  another problem connected with order of execution of declaration
initialization vs.. constructor (imho allowing declaration initialization
for class members was good idea at all)
LRM doesn't define how it should be done. My guess is that:
1st initialization from declaration should be done in order from base class
to child class 
2nd constructor chain should be executed - as described in LRM from base to
child
 
Rules for the order are clear for classes which do not inherit other class -
LRM:
"Class properties that include an initialize in their declaration are
initialized before the execution of the user defined class constructor.
Thus, initializer values can be overridden by the class constructor."
 
But for classes inheriting some other class LRM says:
"Every class has a default (built-in) new method. The default constructor
first calls its base class constructor (super.new() as described in 8.14)
and then proceeds to initialize each member of the current object to its
default (or uninitialized value)."
Most interesting is "proceeds to initialize each member of the current
object to its default (or uninitialized value)." I thought that
uninitialized value is same as default, anyway why constructor need to do
some initialization if the value should be default (which means that value
is hold in variable if no initialization or assignment was done  ).
But one can understand this sentence differently - default value is a value
from initialization at declaration - because it has to be assigned - if so
then results for below code would be : 123 0 123 123 
 
I totally don't understand what was the goal of adding this sentence to LRM.
 
 
CODE:
module top;
        class C;
                int i=123;
                function new(input int v);
                        $display("C %d", i);
                        $display("C %d", v);
                endfunction
        endclass
 
        class CC extends C;
                int j=i;
                function new;
                        super.new(j);
                        $display("CC %d",i);
                        $display("CC %d",j);
                endfunction
        endclass
 
        CC c = new;
endmodule

IMHO Expected results are:
123
123
123
123
 
What should be the results in your opinion? 
Is the LRM description clear in this matter in your opinion?
Do you finding class member initialization at declaration useful feature -
or are you regretting that someone have vote it in into the standard ?
 
 
DANiel

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Thu Aug 28 08:10:23 2008

This archive was generated by hypermail 2.1.8 : Thu Aug 28 2008 - 08:10:49 PDT