Member function increases size of a struct defined in a function - is this a bug?
Max Samukha
maxsamukha at gmail.com
Fri Feb 7 21:31:43 UTC 2020
On Friday, 7 February 2020 at 18:58:54 UTC, H. S. Teoh wrote:
> On Fri, Feb 07, 2020 at 12:50:11PM +0000, Max Samukha via
> Digitalmars-d wrote:
>> On Friday, 7 February 2020 at 12:36:23 UTC, Ferdinand Majerech
>> wrote:
>> >
>> > Is this the result of some D feature?
>> > I can imagine this could happen if InnerFun had a silently
>> > added
>> > context pointer, but I don't know of such a feature in D.
>> >
>>
>> A pointer to the environment is a added to InnerFun for some
>> reason
>> (probably, a bug).
>
> It's not a bug; the struct is declared inside function scope,
> and so member functions can access function local variables.
> Therefore a context pointer is necessary.
>
It is not necessary in this case, because the member function
doesn't reference any variables in the outer function.
>
>> You can work around by marking InnerFun 'static':
> [...]
>
> 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.
>
> T
More information about the Digitalmars-d
mailing list