Calling nested function before declaration

Jonathan JonathanILevi at gmail.com
Wed Sep 26 22:46:21 UTC 2018


This code fails to compile: ("undefined identifier fun")
void main() {
     fun();
     void fun() {}
}

Having the call after the declaration works:
void main() {
     void fun() {}
     fun();
}

Is this how it is intended to work?

It seems goofy that this works:
void main() {
     void fun2() {}
     void fun() {
          fun2()
     }
     fun();
}

But this fails to compile: ("undefined identifier fun2")
void main() {
     void fun() {
          fun2()
     }
     void fun2() {}
     fun();
}

What if I wanted this?
void main() {
     void fun2() {fun();}
     void fun() {fun2();}
     fun();
}

I can't see how the current behavior is at all better or to be 
preferred unless it is faster to compile?  What is the reason for 
it being how it is?


More information about the Digitalmars-d mailing list