"Lazy" initialization of structs

Era Scarecrow via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 1 05:12:21 PDT 2017


On Thursday, 1 June 2017 at 12:04:05 UTC, Daniel Tan Fook Hao 
wrote:
> If I'm reading this right, in the former, the struct is created 
> when the function is called in run-time, and the type is then 
> inferred after that? I don't really understand the behavior 
> behind this.

  The only difference between the two, is the inner struct can 
hold a delegate or a pointer to the function's local variables. 
If you make the first example 'static struct' then the two are 
100% identical (with the exception of visibility of who can 
see/initiate the struct).

  Although since there's no function calls from the struct I don't 
see how it should act any different, though that might not 
prevent it from throwing the pointer there anyways.


More information about the Digitalmars-d-learn mailing list