Hi Axel, Axel Freyn escribió:
[CUT] > I simply added debug output before/after each "event" > My gcc-generated executable says the following at runtime: > main 1 > type_schema called the 1 time > type_schema 1 > Contructor called the 1 time > Constructor sponge_object_schema: 1 > type_schema called the 2 time > type_schema 1 > terminate called after throwing an instance of > '__gnu_cxx::recursive_init_error' > what(): std::exception Well, MSVS2010 returned this result: main 1 type_schema called the 1 time type_schema 1 Contructor called the 1 time Constructor sponge_object_schema: 1 type_schema called the 2 time type_schema 1 type_schema 2 Constructor sponge_object_schema: 3 type_schema 2 main 2 This is very very strange, because after the second "type_schema 1", when the execute line of the debug is on line: static sponge_object_schema result; it isn't call a "sponge_object_schema" constructor, and then the program follow the standard execution. > This seems to me the only "clean" solution to this problem... > I would really be interested what MSVS is doing to overcome this > problem? No matter what he does, it IS dangerous (I think...): > 1) if he outputs "type_schema 2" BEFORE "Constructor > sponge_object_schema: 3" that would mean that he ignored the constructor > in "type_schema" before the constructor is finished ==> it would be very > dangerous to use the static variable "result" there, as its not yet > completely constructed... This is that he does!, at least I think, and I don't understand why you think it's very dangerous. > 2) if he outputs "type_schema 2" AFTER "Constructor > sponge_object_schema: 3" that would mean that he ignored the call to > "type_schema" in the constructor ==> it do not see any possible > explanation why that would be justified or reasonable ... It isn't the case. > (Well, mabye there is some paragraph somewhere in the C++-standard which > defines this situation as "undefined behaviour"? Then the compiler could > of course do whatever he wants...) Maybe it's possible, though, I searched in the working draft of standard programming c++ of this year that: "Static initialization shall be performed before any dynamic initialization takes place. Dynamic initialization of non-local variable with static storage duration is either ordered or unordered. Definitions of explicitly specialized class template static data members have ordered initialization." > Best Regards, > Axel -- Best regards, Gilberto Cuba Ricardo