Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 28, 2003 DMD 0.61 Bug | ||||
---|---|---|---|---|
| ||||
The following code: class MyClass { uint myFunc() { uint myInt = 13; uint mySubFunc() { return myInt; } return mySubFunc(); } } int main() { MyClass myInstance = new MyClass; printf("%i", myInstance.myFunc()); return 0; } Should print 13. It prints 4202543 instead. =) If I move "uint myInt = 13;" from myFunc's to MyClass's scope it works correctly. I hope I haven't reported an already reported bug. |
April 28, 2003 Re: DMD 0.61 Bug | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | I was using printf's to try to see what was going on.
class MyClass
{
uint myFunc()
{
uint myInt = 13;
//printf("%d\n", myInt);
uint mySubFunc()
{
printf("%d\n", myInt);
return myInt;
}
//printf("%d\n", myInt);
return mySubFunc();
}
}
int main(char[][] args)
{
MyClass myInstance = new MyClass;
printf("%i", myInstance.myFunc());
return 0;
}
Run this and it returns:
4202571
4202571
Uncomment one of the other printf's and I get:
13
13
13
What would cause that?
Dario wrote:
> The following code:
> class MyClass
> {
> uint myFunc()
> {
> uint myInt = 13;
> uint mySubFunc()
> {
> return myInt;
> }
> return mySubFunc();
> }
> }
> int main()
> {
> MyClass myInstance = new MyClass;
> printf("%i", myInstance.myFunc());
> return 0;
> }
> Should print 13. It prints 4202543 instead. =)
> If I move "uint myInt = 13;" from myFunc's to MyClass's scope it works
> correctly.
> I hope I haven't reported an already reported bug.
>
>
|
April 28, 2003 Re: DMD 0.61 Bug | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | Try this:
class MyClass
{
uint myFunc()
{
uint myInt = 13;
uint mySubFunc()
{
printf("%d\n", *(&myInt + 2));
printf("%d\n", myInt);
return myInt;
}
return mySubFunc();
}
}
int main(char[][] args)
{
MyClass myInstance = new MyClass;
printf("%i", myInstance.myFunc());
return 0;
}
Prints:
13
4202599
4202599
The first line is whatever number I have initialized myInt with.
Dario wrote:
> The following code:
> class MyClass
> {
> uint myFunc()
> {
> uint myInt = 13;
> uint mySubFunc()
> {
> return myInt;
> }
> return mySubFunc();
> }
> }
> int main()
> {
> MyClass myInstance = new MyClass;
> printf("%i", myInstance.myFunc());
> return 0;
> }
> Should print 13. It prints 4202543 instead. =)
> If I move "uint myInt = 13;" from myFunc's to MyClass's scope it works
> correctly.
> I hope I haven't reported an already reported bug.
>
>
|
Copyright © 1999-2021 by the D Language Foundation