Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
January 20, 2007 Stack overflow error | ||||
---|---|---|---|---|
| ||||
The following code: void f() { f; } void main() { f(); } compiled by DMD v1.0 (on Windows XP) generates an "Error: Stack Overflow" error. |
January 20, 2007 Re: Stack overflow error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marcio Faustino | 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.
|
January 20, 2007 Re: Stack overflow error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marcio Faustino | 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
|
January 20, 2007 Re: Stack overflow error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | 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.
|
January 20, 2007 Re: Stack overflow error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marcio Faustino | 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
|
January 21, 2007 Re: Stack overflow error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | 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 ? -- |
January 21, 2007 Re: Stack overflow error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey Khropov | "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. |
January 22, 2007 Re: Stack overflow error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey Khropov | 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
|
Copyright © 1999-2021 by the D Language Foundation