www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Stack overflow error

reply Marcio Faustino <m.faustino.remove-this gmail.com> writes:
The following code:
void f() { f; }
void main() {
    f();
}

compiled by DMD v1.0 (on Windows XP) generates an "Error: Stack Overflow" error.
Jan 20 2007
next sibling parent Johan Granberg <lijat.meREM OVE.gmail.com> writes:
Marcio Faustino wrote:

 The following code:
 void f() { f; }
 void main() {
     f();
 }
 
 compiled by DMD v1.0 (on Windows XP) generates an "Error: Stack Overflow"
 error.
This is a programmer error. you are calling the function f within the function f causing an infinite recursion.
Jan 20 2007
prev sibling parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Marcio Faustino wrote:
 The following code:
 void f() { f; }
 void main() {
     f();
 }
 
 compiled by DMD v1.0 (on Windows XP) generates an "Error: Stack Overflow"
error.
Are you saying you'd like D to implement the tail recursion elimination optimization? Because most C/C++ compilers would probably generate a stack overflow on the equivalent of that code too. Oh, you do realize D treats 'blah' as a synonym for 'blah()' if blah is a function or delegate, right? --bb
Jan 20 2007
next sibling parent reply Marcio Faustino <m.faustino.remove-this gmail.com> writes:
Bill Baxter wrote:
 Oh, you do realize D treats  'blah' as a synonym for 'blah()' if blah > is a
function or delegate, right? Didn't know that, how dumb of me. Sorry.
Jan 20 2007
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Marcio Faustino wrote:
 Bill Baxter wrote:
 Oh, you do realize D treats  'blah' as a synonym for 'blah()' if blah > is a
function or delegate, right? Didn't know that, how dumb of me. Sorry.
No need to apologize. I was surprised by that one too, initially, even though I knew methods could be called without the (). I just didn't expect that would extend to top-level functions too. --bb
Jan 20 2007
prev sibling parent reply "Andrey Khropov" <andkhropov_nosp m_mtu-net.ru> writes:
Bill Baxter wrote:


 Oh, you do realize D treats  'blah' as a synonym for 'blah()' if blah is a
 function or delegate, right?
I think it's a harmful and error-prone feature. And it's also inconsistent: auto f2 = f; // here f is treated like a variable f; // here f means call itself, but it looks exactly the same Why on earth is this needed ? --
Jan 21 2007
next sibling parent "Lionello Lunesu" <lionello lunesu.remove.com> writes:
"Andrey Khropov" <andkhropov_nosp m_mtu-net.ru> wrote in message 
news:ep01si$o08$1 digitaldaemon.com...
 Bill Baxter wrote:


 Oh, you do realize D treats  'blah' as a synonym for 'blah()' if blah is 
 a
 function or delegate, right?
I think it's a harmful and error-prone feature. And it's also inconsistent: auto f2 = f; // here f is treated like a variable f; // here f means call itself, but it looks exactly the same Why on earth is this needed ?
(implicit) properties. #auto f2 = f; // f can be a variable or a property getter (Uhm, that would work, if there weren't that issue with using auto + a getter that way.) I like this feature. It gets rid of many () pairs, and I think it's a straightforward way for properties. L.
Jan 21 2007
prev sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Andrey Khropov wrote:
 Bill Baxter wrote:
 
 
 Oh, you do realize D treats  'blah' as a synonym for 'blah()' if blah is a
 function or delegate, right?
I think it's a harmful and error-prone feature. And it's also inconsistent: auto f2 = f; // here f is treated like a variable f; // here f means call itself, but it looks exactly the same Why on earth is this needed ?
I know what you mean. But it's very handy in the context of methods that masquerade as properties. So you can say obj.prop instead of obj.prop(). I think I would prefer, though, if that feature had to be explicitly enabled for a particular method. Something like: property float prop() { return m_prop; } Then for most functions (which aren't properties) we could dispense with the & required to take the address. On the other hand there is something to be said for consistency and regularity. foo is synonymous with foo() if foo is a function. Period. So I can sorta see why Walter made it the way it is. That and probably it was a lot easier to implement the way it is, since the compiler doesn't have to keep track of whether a function is a 'property' function or not. --bb
Jan 21 2007