Re: Nested function requires forward declaration?

2022-04-14 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 14 April 2022 at 08:55:25 UTC, Chris Katko wrote: [...] It appears the nested function's variable capture depends on forward declaration (the right term?). Whereas, I was under the impression most/all of D worked on a multiple pass compilation so the order of declarations

Re: Nested function requires forward declaration?

2022-04-14 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 14 April 2022 at 08:55:25 UTC, Chris Katko wrote: I imagine this is a really odd edge case but it's piqued my interest. Consider this: ```d void main() { void foo() { initRuntimeState(i); } foo(); if(!modifyRutimeState()) return; int i = getRandomValue(); i =

Re: Nested function requires forward declaration?

2022-04-14 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 14 April 2022 at 08:55:25 UTC, Chris Katko wrote: Using DMD. v2.098-beta-2 Not sure if right terminology. But I just wrote a nested function that uses a variable outside its body. The capture (right term?) is obvious where the invocation is. However, I have to move the

Nested function requires forward declaration?

2022-04-14 Thread Chris Katko via Digitalmars-d-learn
Using DMD. v2.098-beta-2 Not sure if right terminology. But I just wrote a nested function that uses a variable outside its body. The capture (right term?) is obvious where the invocation is. However, I have to move the declaration of the variable to above the nested function for it to