Forward referencing functions in D

Adam D. Ruppe destructionator at gmail.com
Fri Oct 16 20:02:43 UTC 2020


On Friday, 16 October 2020 at 19:55:53 UTC, wilcro wrote:
> Evidently, I am misunderstanding something very elemental here; 
> thanks for any enlightenment regarding this.

Inside a function things happen in order, top to bottom, 
including declarations (you can only access local variables after 
they are declared, and nested functions work like local 
variables).

In a declaration, order is less important.

For recursive nested functions it can sometimes help to put a 
declaration inside a function:

void main() {
   // order matters here, in function
    struct Holder {
        // order doesn't matter in here, in decl
     }
   // order matters again since functions run in sequence
}


More information about the Digitalmars-d-learn mailing list