Calling nested function before declaration

Neia Neutuladh neia at ikeran.org
Wed Sep 26 23:05:45 UTC 2018


On 09/26/2018 03:46 PM, Jonathan wrote:
> 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?

void outerFunction()
{
   func();
   auto lock = acquireLock();
   void nested()
   {
   }
}

Inside `nested`, can you refer to `lock`? It's in lexical scope, so yes. 
It hasn't been initialized yet. What value should it have? Presumably 
its standard uninitialized value.

This is likely to cause a lot of confusion.

The standard ways of dealing with this:

* Reorder the declarations.
* Make the functions non-nested.
* Get rid of mutual recursion.
* Use a delegate.
* Do a method-to-method-object refactoring.


More information about the Digitalmars-d mailing list