Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 20, 2004 default ctor & inheritance bug | ||||
---|---|---|---|---|
| ||||
Code below outputs '1' instead '0'. 'bar' value overrides 'foo' value, when in there are no ctor in class 'B'. If uncomment B ctor, output is '0', as expected. <code> class A { this() {} } class B: A { int foo; // this() {} } class C: B { int bar; this() { foo = 0; bar = 1; } } void main() { C c = new C(); printf("%d", c.foo); // 1, expecting 0 } </code> |
December 21, 2004 Re: default ctor & inheritance bug - Cannot reproduce | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Zaitseff | On Tue, 21 Dec 2004 00:10:47 +1000, Ilya Zaitseff <sark7@mail333.com> wrote: > Code below outputs '1' instead '0'. > > 'bar' value overrides 'foo' value, when in there are no ctor in class 'B'. > If uncomment B ctor, output is '0', as expected. > > <code> > class A > { > this() {} > } > > class B: A > { > int foo; > // this() {} > } > > class C: B > { > int bar; > > this() > { > foo = 0; > bar = 1; > } > } > > void main() > { > C c = new C(); > printf("%d", c.foo); // 1, expecting 0 > } > </code> dmd 0.109 on XP outputs 0. What version do you use? -- "Unhappy Microsoft customers have a funny way of becoming Linux, Salesforce.com and Oracle customers." - www.microsoft-watch.com: "The Year in Review: Microsoft Opens Up" -- "I plan on at least one critical patch every month, and I haven't been disappointed." - Adam Hansen, manager of security at Sonnenschein Nath & Rosenthal LLP (Quote from http://www.eweek.com/article2/0,1759,1736104,00.asp) -- "It's been a challenge to "reteach or retrain" Web users to pay for content, said Pizey" -Wired website: "The Incredible Shrinking Comic" |
December 22, 2004 Re: default ctor & inheritance bug - Cannot reproduce | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simon Buchan | On Tue, 21 Dec 2004 19:36:19 +1300, Simon Buchan <currently@no.where> wrote:
> On Tue, 21 Dec 2004 00:10:47 +1000, Ilya Zaitseff <sark7@mail333.com> wrote:
>
>> Code below outputs '1' instead '0'.
>>
>> 'bar' value overrides 'foo' value, when in there are no ctor in class 'B'.
>> If uncomment B ctor, output is '0', as expected.
>>
>> <code>
>> class A
>> {
>> this() {}
>> }
>>
>> class B: A
>> {
>> int foo;
>> // this() {}
>> }
>>
>> class C: B
>> {
>> int bar;
>>
>> this()
>> {
>> foo = 0;
>> bar = 1;
>> }
>> }
>>
>> void main()
>> {
>> C c = new C();
>> printf("%d", c.foo); // 1, expecting 0
>> }
>> </code>
>
> dmd 0.109 on XP outputs 0. What version do you use?
>
Strange, on the other machine there is no such bug.
Maybe my D installation is broken.
|
December 22, 2004 Re: default ctor & inheritance bug - Cannot reproduce | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Zaitseff | On Wed, 22 Dec 2004 13:27:26 +1000, Ilya Zaitseff <sark7@mail333.com> wrote: <snip> > > Strange, on the other machine there is no such bug. > Maybe my D installation is broken. I am assusming there would have to be for it to do this... compiler version and environment may help (If they are not identical) Also: this may be somewhat like the eax "return" "behavior" (Its a feature, not a bug! :D), i.e. whatever was in eax is returned from void main(). Unless this always happens with different compilations... or something... -- "Unhappy Microsoft customers have a funny way of becoming Linux, Salesforce.com and Oracle customers." - www.microsoft-watch.com: "The Year in Review: Microsoft Opens Up" -- "I plan on at least one critical patch every month, and I haven't been disappointed." - Adam Hansen, manager of security at Sonnenschein Nath & Rosenthal LLP (Quote from http://www.eweek.com/article2/0,1759,1736104,00.asp) -- "It's been a challenge to "reteach or retrain" Web users to pay for content, said Pizey" -Wired website: "The Incredible Shrinking Comic" |
December 23, 2004 Re: default ctor & inheritance bug | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Zaitseff Attachments: | Added to DStress as http://svn.kuehne.cn/dstress/run/constructor_07.d http://svn.kuehne.cn/dstress/run/constructor_08.d Thomas |
Copyright © 1999-2021 by the D Language Foundation