Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 18, 2005 Can't Forward Reference Nested Functions | ||||
---|---|---|---|---|
| ||||
Linux (Fedora Core 1), DMD 0.110 I can't call nested functions that I haven't defined yet. > void main() { > nestedFunc(); > void nestedFunc() {}; > } DMD complains with the following error: > cant_forward_reference_nested_funcs_bug.d(2): undefined identifier nestedFunc > cant_forward_reference_nested_funcs_bug.d(2): function expected before (), not 'int' |
January 19, 2005 Re: Can't Forward Reference Nested Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | In article <csk4ne$2njc$2@digitaldaemon.com>, Russ Lewis says... > >Linux (Fedora Core 1), DMD 0.110 > >I can't call nested functions that I haven't defined yet. > >> void main() { >> nestedFunc(); >> >> void nestedFunc() {}; >> } > >DMD complains with the following error: > >> cant_forward_reference_nested_funcs_bug.d(2): undefined identifier nestedFunc >> cant_forward_reference_nested_funcs_bug.d(2): function expected before (), not 'int' > Perhaps the error message could be improved, but the spec mentions that this code isn't allowed: "Unlike module level declarations, declarations within function scope are processed in order. This means that two nested functions cannot mutually call each other." (http://www.digitalmars.com/d/function.html) Hopefully someday we'll be able to use nested functions before they are defined, but at least this limitation is mentioned in the spec. jcc7 |
January 19, 2005 Re: Can't Forward Reference Nested Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | J C Calvarese wrote:
> Perhaps the error message could be improved, but the spec mentions that this
> code isn't allowed:
>
> "Unlike module level declarations, declarations within function scope are
> processed in order. This means that two nested functions cannot mutually call
> each other." (http://www.digitalmars.com/d/function.html)
>
> Hopefully someday we'll be able to use nested functions before they are defined,
> but at least this limitation is mentioned in the spec.
Hmmm. Didn't notice that. Well, I guess that it's fair if it's documented :/
I am very curious though, Walter, what the reason for this is. Just speaking as a programmer, I'd be fascinated to understand why this requirement exists. It would seem (from the outside) that whatever code you use use handle forward references in general could be leveraged to also handle this case.
|
January 20, 2005 Re: Can't Forward Reference Nested Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:csm3d1$2oda$1@digitaldaemon.com... > I am very curious though, Walter, what the reason for this is. Just speaking as a programmer, I'd be fascinated to understand why this requirement exists. It would seem (from the outside) that whatever code you use use handle forward references in general could be leveraged to also handle this case. To fix it, the semantic pass for function bodies would have to be rewritten to be multipass, and it seems a low priority to do that. |
Copyright © 1999-2021 by the D Language Foundation