digitalmars.D.bugs - Nested functions bug
- Alexei Averchenko (5/5) Jan 18 2007 I discovered an issue with nested functions: they must be declared
- Frits van Bommel (24/29) Jan 18 2007 http://www.digitalmars.com/d/function.html#nested (at the end of the
- Alexei Averchenko (2/5) Jan 18 2007 I understand. But the thing is I can't call nested function even from th...
- Frits van Bommel (3/10) Jan 18 2007 I think that's the *entire* limitation. Not being able to call it from a...
I discovered an issue with nested functions: they must be declared before used. Is this a bug or a lenguage limitation. Whatever it is, please resolve this issue, because it screwes the very idea of nested functions, making it hard to read and maintain the code. Thanks in advance.
Jan 18 2007
Alexei Averchenko wrote:I discovered an issue with nested functions: they must be declared before used. Is this a bug or a lenguage limitation. Whatever it is, please resolve this issue, because it screwes the very idea of nested functions, making it hard to read and maintain the code. Thanks in advance.http://www.digitalmars.com/d/function.html#nested (at the end of the section): ***** Unlike module level declarations, declarations within function scope are processed in order. This means that two nested functions cannot mutually call each other: void test() { void foo() { bar(); } // error, bar not defined void bar() { foo(); } // ok } The solution is to use a delegate: void test() { void delegate() fp; void foo() { fp(); } void bar() { foo(); } fp = &bar; } Future directions: This restriction may be removed. ***** So it's a limitation. Someday it may be removed, but until then there's a workaround available.
Jan 18 2007
Frits van Bommel Wrote:Unlike module level declarations, declarations within function scope are processed in order. This means that two nested functions cannot mutually call each other:I understand. But the thing is I can't call nested function even from the function in which it was declared before the declaration. Is this the limitation too?
Jan 18 2007
Alexei Averchenko wrote:Frits van Bommel Wrote:I think that's the *entire* limitation. Not being able to call it from a nested function defined before it is just one manifestation of it.Unlike module level declarations, declarations within function scope are processed in order. This means that two nested functions cannot mutually call each other:I understand. But the thing is I can't call nested function even from the function in which it was declared before the declaration. Is this the limitation too?
Jan 18 2007