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

Steven Schveighoffer schveiguy at gmail.com
Fri Feb 7 21:38:52 UTC 2020


On 2/7/20 4:31 PM, Max Samukha wrote:
> On Friday, 7 February 2020 at 18:58:54 UTC, H. S. Teoh wrote:
>> Yes, this disables access to function local variables from inside the 
>> struct, so it eliminates the context pointer.
>>
> 
> Yes, but the compiler could infer that the context pointer is not 
> necessary. Maybe it can't, who knows. The bug report has been open for 7 
> years without any response from language maintainers.

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.

-Steve


More information about the Digitalmars-d mailing list