Puzzled by this behavior

Steven Schveighoffer schveiguy at gmail.com
Wed Jun 1 00:38:41 UTC 2022


On 5/31/22 8:29 PM, Steven Schveighoffer wrote:

> However, thinking about it more, we *do* allow function prototypes as 
> local functions. But I can't figure out a way to actually define them, 
> aside from using pragma(mangle).
> 
> I think there's an opportunity here where we can allow function 
> prototypes, allow definitions later, and not break existing code.

Oh my, I just realized, a function prototype that's later defined could 
end up using stack frame data that doesn't exist. This is the reason for 
not allowing prototypes or forward reference functions:

```d
void foo()
{
   void bar();
   bar(); // would affect x before it exists
   int x = 5;
   void bar() { ++x; }
}
```

So just use a static struct if you want mutual recursion.

-Steve


More information about the Digitalmars-d mailing list