|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
D.gnu - Local variabled and nested functions
This small test-case:
import std.stdio;
int foo(int a) {
int bar(int b) {
a += b;
if (b > 0) {
return bar(b - 1);
} else {
return a;
}
}
return bar(a);
}
int main(char[][] args) {
writefln("a=", foo(3));
return 0;
}
Correctly gives "a=9" on gdc 0.15. But "a=72592" on gdc 0.16.
Same goes for the smaller example (with purely local variable):
int bar() {
int a = 1;
int baz(bool onemore) {
if (onemore)
return baz(false);
else
return a;
}
return baz(true);
}
Should always give 1, but mostly gives 72504 for me. I guess the pointer
to the parents locals get screwed up. It works as long as I do not use
recursion.
regards
Fredrik Olsson
Nov 29 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Fredrik Olsson schrieb am 2005-11-30: Dec 04 2005
|