Member function increases size of a struct defined in a function - is this a bug?

Steven Schveighoffer schveiguy at gmail.com
Fri Feb 7 22:41:25 UTC 2020


On 2/7/20 5:27 PM, Max Samukha wrote:
> On Friday, 7 February 2020 at 21:38:52 UTC, Steven Schveighoffer wrote:
> 
>>
>> There are some cases in D which *could* be done with enough analysis, 
>> but aren't because it would complicate the compiler for little benefit 
>> (or make the language dependent on how clever the compiler is).
>>
>> This is one of those cases. Just add static to the struct declaration.
>>
> 
> What analysis? Doesn't compiler already know the set of variables in the 
> closure environment?

Yeah true. It would have to, while compiling the struct functions, add 
references to the closure, which means it would know if any exists by 
the time it's done compiling the struct functions.

However, it might need to know that before compiling.

It could really be based on how the compilation is implemented, making 
it difficult to figure this out.

The "add a closure reference if there are any functions" seems like a 
really easy thing to just do and not worry about it. And honestly, just 
putting static in front of the struct is also easy.

-Steve


More information about the Digitalmars-d mailing list